开发者社区> 问答> 正文

关于UITableViewCell 为所有单元设置图片 的问题

给所有的UITableViewCell 背景图片设置成同样的,代码:

- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    cell.backgroundView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"SelectAnAlbumTableViewCellBackground"]] autorelease];
}

对其中一些有效,但是对是空的cell就无效。不知道怎么样可以对所以的背景设置同样的图片?

展开
收起
爵霸 2016-03-23 11:28:11 1713 0
1 条回答
写回答
取消 提交回答
  • 首先,设置cellbackgroundView 放到函数
    `-(void)tableView:(UITableView )tableView cellForRowAtIndex:(NSIndexPath ) indexPath
    `

    中来处理比较好点.
    再者,对于空的cell是不会被调用cellForRowAtIndexPath: or willDisplayCell: 消息的.所以你设置backgroundview的方法也就起不到作用.

    2019-07-17 19:10:37
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载