【发布时间】:2014-06-18 22:47:38
【问题描述】:
我有一个UITableView,有 4 个部分。其中三个部分有一个标题视图。
标题视图是UITableViewCell,我将其作为viewForHeaderInSection: 委托中的普通单元格出列。
如果我从任何部分插入或删除一行,其他 tableview 标题单元格就会消失。
我假设这与单元格重用有关,但是单元格最初都出现在屏幕上(所有三个标题同时出现在屏幕上)。
我尝试在插入或删除后重新加载其他部分,但这没有帮助。
这里有一些代码:
- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
switch (section) {
case kSectionCardInformation:
case kSectionContactInformation:
case kSectionTags: {
static NSString *CellIdentifier = @"EditContactHeaderCell";
EditContactHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
return cell;
}
default:
return nil;
}
}
这里是我删除相关部分中的行的地方:
- (void)deleteTag:(CDTag *)tag {
[self.tableView beginUpdates];
NSMutableArray *objects = [self.sections objectAtIndex:kSectionTags];
if ([objects containsObject:tag]) {
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:[objects indexOfObject:tag] inSection:kSectionTags];
[objects removeObject:tag];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationMiddle];
[self.contact deleteTag:tag];
}
[self.tableView endUpdates];
}
任何帮助,不胜感激。
【问题讨论】:
-
我发现使用不是 UITableViewCell 子类的视图可以解决这个问题。但我不明白为什么。
标签: ios objective-c uitableview