我有一個selectedArray定義爲我的文件中的一個屬性,它保存哪些單元格已被「檢查」。當顯示單元格時,我檢查當前單元格值是否在selectedArray中,如果是,則顯示UITableViewCellAccessoryCheckmark作爲表格的附件視圖。UITableView不適當刷新
唯一的問題是,當用戶使用UISearchBar通過UITableView進行搜索時,我會要求表reloadData完成搜索後,並且在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];
感謝您填補我答案中的空白。 – Justin 2010-08-11 12:01:22