首先,我刪除tableView中的一個單元格,然後我想在tableView中添加另一個新單元格,但新單元格不是新的,它只是我刪除的單元格。我知道什麼dequeueReusableCellWithIdentifier means.i認爲當刪除一個單元格時,dequeueReusableCellWithIdentifier中的緩存也被刪除。爲什麼不呢?在tableview中刪除單元格,單元格也可以重用,爲什麼?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"table reload");
PDFModel* tempmodel=[PDFArray objectAtIndex:indexPath.row];
NSString * CellIdentifier=tempmodel.PDFName;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
NSLog(@"cell %x",cell);
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
//custom the cell
cell.text=...
}
return cell;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle==UITableViewCellEditingStyleDelete)
{
[PDFArray removeObjectAtIndex:indexPath.row];
NSMutableArray* array=[[NSMutableArray alloc] init];
[array addObject:indexPath];
[self.tableView deleteRowsAtIndexPaths:array withRowAnimation:UITableViewRowAnimationRight];
}
}
你不應該返回細胞形成,如果你在那裏,如果你有一個取出的細胞檢查的語句。只需設置所有單元格屬性即可。 – rckoenes 2011-04-12 11:22:27
此方法表明您要重用單元格 UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; – GameLoading 2011-04-26 08:31:47