How to change UITableViewCell appearance if cellFo

2020-05-06 08:42发布

问题:

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?

回答1:

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.



回答2:

Did you try to subclass your tableview cells and set their background in their initializer?