如果cellForRowAtIndexPath没有调用,如何更改UITableViewCell外观 [英] How to change UITableViewCell appearance if cellForRowAtIndexPath is not calling

查看:182
本文介绍了如果cellForRowAtIndexPath没有调用,如何更改UITableViewCell外观的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用中有一个表格视图。表格视图单元格具有图案图像的背景。表视图内容正在发生变化,有时只有两个或三个单元格包含内容信息。并且表格视图会自动将其他单元格添加到屏幕底部。问题是这些细胞的背景是清晰的,但我想使背景与其他细胞相同(带有图案图像)。通常我会在cellForRowAtIndexPath中更改单元格外观。但是表视图不会为自动创建的单元格调用此方法。那么,有什么解决方案吗?

I have a table view in my app. The table view cells has background with pattern image. Table view content is changing and sometimes there are only two or three cells with content info. And table view automatically add other cells to bottom of screen. The problem is the background of these cells is clear but i want to make background same as other cells (with pattern image). Usually i change cells appearance in cellForRowAtIndexPath. But table view don'call this method for cells that created automatically. So, is there any solution?

推荐答案

你可以在viewDidLoad()中执行此操作
self.searchDisplayController.searchResultsTableView.backgroundColor = [UIColor redColor]; //在此处为tableview设置颜色
这应该将搜索结果表格单元格设置为您偏好的颜色。您可以使用的另一个委托是:
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

cell.backgroundColor = [UIColor redColor]; //你的颜色在这里
}

希望这有帮助。

You could do this in viewDidLoad() self.searchDisplayController.searchResultsTableView.backgroundColor = [UIColor redColor]; // set your color for tableview here
This should color the search results table cells to the color of your preference. Another delegate you could investigate using is:
- (void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.backgroundColor = [UIColor redColor]; // your color here }

Hope this helps.

这篇关于如果cellForRowAtIndexPath没有调用,如何更改UITableViewCell外观的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆