Ios 更改整个应用程序UITableViewCell的背景视图

Ios 更改整个应用程序UITableViewCell的背景视图,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我有下面的方法,它适合我想要的 -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath { UIView *colorView = [[UIView alloc] init]; colorView.backgroundColor = [UIColor darkGrayColor];

我有下面的方法,它适合我想要的

-(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

使用外观API:

[[UITableViewCell appearance] setBackgroundColor:[UIColor darkGrayColor]];
大多数情况下,您还需要设置
UITableView
背景色,但这取决于您的需要:

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

您只需使用
[UITableViewCell外观]
。谢谢,这很有效。添加此代码的最佳位置是哪里<代码>应用委派
rootViewController
?只要在显示任何表视图之前执行它,两者都可以。就我个人而言,如果可能的话,我喜欢避免在app delegate中放入太多内容。