【发布时间】:2014-08-27 15:09:52
【问题描述】:
Xcode 6 beta 6,尝试在外观代理中更改所有 UITableView 的背景颜色:
[[UITableView appearance] setBackgroundColor:[UIColor redColor]]
但是好像不行。
重现步骤:
1 创建单视图项目
2 在 storyboard
中将 UITableView 添加到 ViewController3 在 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;
}
5 应用内委托:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[[UITableView appearance] setBackgroundColor:[UIColor redColor]];
return YES;
}
6 运行应用程序并观察不正确的颜色:
有什么建议可以解决吗? 为每个表格设置背景颜色看起来不是很好的解决方案。
【问题讨论】:
-
它只发生在 iOS 8.0.x 上,这是错误的,在更低或更高版本的 8.0.x 中没有产生,我认为大多数用户升级到 8.1 所以完全不用担心:)
-
根据this 的问题,这似乎是一个错误。 rdar://18406065
-
我在物理设备和模拟器上的 iOS 8.1.X 和 8.2.X 中仍然遇到 UITableView 外观背景颜色问题。但是它在上面工作正常。我必须以编程方式保留
[tableview setBackgroundColor: ]。 -
popei,问题是如何在外观代理中自动完成
标签: ios objective-c iphone uitableview ios8