iOS 8 UITableView背景色外观

Hot*_*ard 20 iphone objective-c uitableview ios ios8

Xcode 6 beta 6,尝试在外观代理中更改所有UITableView的背景颜色:

[[UITableView appearance] setBackgroundColor:[UIColor redColor]]
Run Code Online (Sandbox Code Playgroud)

但似乎它不起作用.

重现步骤:

1创建单个视图项目

2在故事板中将UITableView添加到ViewController

3将代理设置为查看控制器并更改IB中的背景:

在此输入图像描述

4添加动态单元并配置数据源:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"Cell1Identifier" forIndexPath:indexPath];
  return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  return 60.f;
}
Run Code Online (Sandbox Code Playgroud)

5在app委托中:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  // Override point for customization after application launch.
  [[UITableView appearance] setBackgroundColor:[UIColor redColor]];

  return YES;
}
Run Code Online (Sandbox Code Playgroud)

6运行app并观察不正确的颜色:

在此输入图像描述

任何建议如何解决?为每个表设置背景颜色看起来不是一个好的解决方案.

Cha*_*aka 11

尝试在InterfaceBuilder中将BackgroundColor"重置"为"Default"(即使它已经默认,你会看到一点颜色变化)

这不适用于分组样式表视图

更新:

这对我有用

[[UIScrollView appearance] setBackgroundColor:[UIColor redColor]];
Run Code Online (Sandbox Code Playgroud)

  • 即使使用默认颜色,它现在也无法正常工作. (3认同)

Meg*_*ind 5

TableViewCell的清晰颜色在XCode 6中无法在Tablet中运行.以下解决方法为我解决了问题.

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

     cell.backgroundColor = [UIColor redColor];
}
Run Code Online (Sandbox Code Playgroud)