【发布时间】:2010-08-11 02:48:38
【问题描述】:
我有一个 selectedArray 定义为我的文件中的一个属性,它保存了哪些单元格已被“检查”。在显示单元格时,我检查当前单元格值是否在 selectedArray 中,如果是,我将 UITableViewCellAccessoryCheckmark 显示为表格的附件视图。
唯一的问题是,当用户使用 UISearchBar 通过 UITableView 进行搜索时,我要求表在完成搜索后重新加载数据,并且在 numberofRows 方法中,我看到 selectedArray 中的对象数量正确。但是,cellForRowatIndexPath 方法仍然显示旧的复选标记,就好像 selectedArray 从未更新过一样。
任何人都可以帮助我吗?这是我的代码 -
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];
【问题讨论】:
标签: objective-c iphone uitableview ios4