Joh*_*ith 5 iphone cocoa-touch uitableview
我有一个UITableView,我通过它设置了背景色
UIView *myView = [[UIView alloc] init];
if ((indexPath.row % 2) == 0)
myView.backgroundColor = [UIColor greenColor];
else
myView.backgroundColor = [UIColor whiteColor];
cell.backgroundView = myView;
[myView release];
Run Code Online (Sandbox Code Playgroud)
我发现的问题是,当我编辑表(通过setEditing:YES ...)时,某些颜色不变的单元格彼此相邻。如何强制UITableView完全重绘。reloadData做得不好。
是否有深层清洁重绘?
我之前也遇到过这个问题,所以我分享一下我是如何解决的:
您可以使用布尔标志(假设它被称为needsRefresh)来控制单元格创建的行为-cellForRowAtIndexPath:
一个例子:
- (UITableViewCell*) tableView:(UITableView *) tableView cellForRowAtIndexPath:(NSIndexPath*) indexPath {
UITableViewCell *cell = [tableView dequeueResuableCellWithIdentifier:SOME_ID];
if(!cell || needsRefresh) {
cell = [[[UITableViewCell alloc] init....] autorelease];
}
//.....
return cell;
}
Run Code Online (Sandbox Code Playgroud)
因此,当您需要硬重新加载时,请将needsRefresh标志设置为YES。简单如痘痘。
| 归档时间: |
|
| 查看次数: |
5478 次 |
| 最近记录: |