带有不带cellForRowAtIndexPath的静态单元的UITableView。 如何设置清晰的背景?
我有一个静态的UITableView,一切都在故事板上。 在cellForRowAtIndexPath我只是使用
return [super tableView:tableView cellForRowAtIndexPath:indexPath];
和桌面视图效果很好。 但是我想设置单元格背景为[UIColor clearColor]我该怎么做? 该表有30个单元格,每个单元格不同。
谢谢
我不完全确定这是否可行,因为我从来没有尝试过使用super
pipe理单元。 如果你的代码和super
,那么你应该能够做到这一点来设置背景颜色:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell *cell = [super tableView:tableView cellForRowAtIndexPath:indexPath]; cell.backgroundColor = [UIColor clearColor]; return cell; }
不pipe怎样,在我看来,这似乎是一种奇怪的做事方式。 通常情况下,这些单元格是根据默认的UITableView
boiletplate代码在方法本身中创build和重用的,不需要调用super
。
试试这个委托方法:
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { cell.backgroundColor = [UIColor clearColor]; }
你可以设置一个方法,并在你的viewDidLoad中调用它,以获得所有的单元格,并做任何你想要的,你可以使用它:
NSArray *visibleIndexPaths = [self.tableView indexPathsForVisibleRows];
获取当前可见单元格的所有索引path
然后按照以下方式对它们进行迭代
UITableViewCell *cell = nil; for (int i = 0; i < 30; i++) { cell = [self.tableView cellForRowAtIndexPath:[visibleIndexPaths objectAtIndex:i]]; // Do your setup }
您也可以参考这个苹果开发者文档的“ 静态行内容的技术 ”