0

reloadRowsAtIndexPaths crashes when i am selecting the cell and check mark is displayed. Below code snippet. let me know what is going wrong.

 

– (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

static NSString *identifier = @”pesticideEntry”;

UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifier];

if(!cell)

{

cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];

cell.selectionStyle=UITableViewCellSelectionStyleNone;

cell.textLabel.backgroundColor = CLEARCOLOR;

}

NSString *pickerData = nil;

if(searchMode)

pickerData = [self.searchArray objectAtIndex:indexPath.row];

else

pickerData = [self.data objectAtIndex:indexPath.row];

cell.textLabel.text = pickerData;

cell.textLabel.font = TITLE_FONT;

[cell.textLabel setTextColor:FieldInfoTextColor];

cell.accessoryType = UITableViewCellAccessoryNone;

if([self.selectedValues containsObject:pickerData])

{

[cell.textLabel setTextColor:[UIColor grayColor]];

}

else if ([self.selectedValue isEqualToString:pickerData])

{

cell.accessoryType = UITableViewCellAccessoryCheckmark;

}

 

cell.backgroundColor = (indexPath.row%2==0)? DIMMEDBACKGROUND:[UIColor whiteColor];

 

return cell;

}

 

– (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

{

[tableView deselectRowAtIndexPath:indexPath animated:YES];

NSString *pickerData = nil;

if(searchMode)

pickerData = [self.searchArray objectAtIndex:indexPath.row];

else

pickerData = [self.data objectAtIndex:indexPath.row];

UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];

if(![self.selectedValues containsObject:pickerData])

{

if(!self.selectedValue)

{

self.selectedValue = pickerData;

selectedCell.accessoryType = UITableViewCellAccessoryCheckmark;

}

else if([self.selectedValue isEqualToString:pickerData])

{

self.selectedValue = nil;

selectedCell.accessoryType = UITableViewCellAccessoryNone;

}

else

{

[self makeAllTableCellsUnCheck];

self.selectedValue = pickerData;

selectedCell.accessoryType = UITableViewCellAccessoryCheckmark;

}

}

[tableView beginUpdates];

[tableView reloadRowsAtIndexPaths: @[indexPath]

withRowAnimation: UITableViewRowAnimationMiddle];

[tableView endUpdates];

}

GeethaJai asked