I have a selectedArray defined as a property in my file that holds which cells have been "checked". When displaying the cell I check whether or not the current cell value is in the selectedArray, and if it is, I display the UITableViewCellAccessoryCheckmark as the table's Accessory View.
The only problem is, when the user searches for through the UITableView using the UISearchBar, I ask the table to reloadData when they are done searching, and in the numberofRows method I see the right amount of objects in the selectedArray. However, the cellForRowatIndexPath method still displays the old checkmarks as if the selectedArray has never been updated.
Can anyone PLEASE help me? Here's my code -
NSArray *tempArray = [[NSArray alloc] init];
if(tableView == theTable) {
tempArray = [contactsArray objectAtIndex:indexPath.row];
} else {
tempArray = [searchfor_array objectAtIndex:indexPath.row];
}
NSString *cellValue = [tempArray objectAtIndex:0];
static NSString *CellIdentifier;
CellIdentifier = cellValue;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(70, 30, 200, 20)];
name.text = [tempArray objectAtIndex:0];
name.backgroundColor = [UIColor clearColor];
[name setFont:[UIFont fontWithName:@"Helvetica-Bold" size:18]];
[cell.contentView addSubview:name];
[name release];
if([selectedArray containsObject:[tempArray objectAtIndex:0]]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
return cell;
[cell release];
[tempArray release];
[cellValue release];