我有一段时间让单元的backgroundView
显示。UITableViewCell backgroundView绘制矩形不被称为
代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// assume cell is dequeued correctly (i.e. cell != nil)
UIView *backgroundView = [[UIView alloc] initWithFrame:cell.frame];
backgroundView.backgroundColor = [UIColor yellowColor];
cell.backgroundView = backgroundView;
[cell.backgroundView setNeedsDisplay];
return cell;
}
我也- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
试过这个。仍然没有运气。
我试图继承用作backgroundView的UIView
对象,并且确认drawRect
从不被调用。
我没有重载'UITableViewCell'的'drawRect'按我的最后一句话。我用一个子类'UIView'对象作为backgroundView进行测试。从来没有为该自定义视图调用'drawRect'。我不会搞乱单元的内部。 backgroundView是根本没有显示出来,我不知道为什么。 –