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?
Asked
Active
Viewed 265 times
0
-
You can obtain a reference to a cell by calling `cellForRowAtIndexPath:` on your table view instance. – Dec 01 '12 at 15:42
-
It will return nil because formally there is no cell for this index path. As i said, these cells creates without calling cellForRowAtIndexPath. You can see it in Contacts in your phone if you start you start to searching some contact. If only a few contants will be found, other rows will be clear. But in this instance it will be ok, because cell's background are clear by default. – tagirkaZ Dec 01 '12 at 16:02
-
that's not true, if I recall correctly. Please try it. – Dec 01 '12 at 16:04
-
@H2CO3 `cellForRowAtIndexPath:` will only return visible cells. – Adam Johnson Dec 01 '12 at 16:08
-
@AdamJohnson Yes. Isn't OP talking about visible cells here? – Dec 01 '12 at 16:09
2 Answers
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.

batman
- 1,937
- 2
- 22
- 41
0
Did you try to subclass your tableview cells and set their background in their initializer?

Nicolas Manzini
- 8,379
- 6
- 63
- 81