Hello everyone,
I have an issue in creating a CheckMarkAccessoryView in the UITableView.When i select a row in th table,i can get a checked mark for that row,but randomly some other rows in the table also gets the check mark.I want only that cell to get the check mark.How can i do this?I am coding for an exclusive list.The following is the code which i have used.
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if(tableView==tableView1) { return […arraycount1…. ]; } else { return […arraycount2…. ]; } } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; } else { UIView* subview; while ((subview = [[[cell contentView] subviews] lastObject]) != nil) [subview removeFromSuperview]; } if(tableView==tableView1) { cell.textLabel.text=[array1 objectAtIndex:indexPath.row]; } else //Tableview2 { cell.textLabel.text=[array2 objectAtIndex:indexPath.row]; } cell.textLabel.font=[UIFont fontWithName:@"Georgia" size:20]; cell.textLabel.textAlignment=UITextAlignmentLeft; [cell setSelectedBackgroundView:border]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *oldCell = [tableView cellForRowAtIndexPath:lastindex]; if (oldCell.accessoryType == UITableViewCellAccessoryCheckmark); { oldCell.accessoryType = UITableViewCellAccessoryNone; } UITableViewCell *newCell = [tableView cellForRowAtIndexPath:indexPath]; if (newCell.accessoryType == UITableViewCellAccessoryNone) { newCell.accessoryType = UITableViewCellAccessoryCheckmark; } }
Kindly correct me where i am going wrong. Thanks in advance for all the experts.