2014-09-01 55 views
0

我有以下方法,它适用于我想要的。更改整个应用程序的UITableViewCell的背景视图

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UIView *colorView = [[UIView alloc] init]; 
    colorView.backgroundColor = [UIColor darkGrayColor]; 
    [cell setSelectedBackgroundView:colorView]; 
    cell.selectedBackgroundView = colorView; 
} 

现在,有没有办法模仿这种行为对整个应用程序,而不是增加这种方法每tableViewController

回答

2

使用外观API:

[[UITableViewCell appearance] setBackgroundColor:[UIColor darkGrayColor]]; 

大多数时候,你要设置UITableView背景颜色,以及时间,但这取决于你的需求:

[[UITableView appearance] setBackgroundColor:[UIColor darkGrayColor]]; 
+0

你可以只用'[的UITableViewCell外观]'。 – 2014-09-01 23:12:06

+0

谢谢,这工作。哪里是添加此代码的最佳地点? 'AppDelegate'? 'rootViewController'? – Jorge 2014-09-01 23:22:42

+1

只要你在显示任何表格视图之前执行它,任何一个都可以。就我个人而言,如果可能的话,我喜欢避免将过多的东西放入应用程序代理中。 – keeshux 2014-09-01 23:25:46