Ste*_*Ojo 5 objective-c ios unrecognized-selector ios8
-(void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section{
UITableViewHeaderFooterView *headerIndexText = (UITableViewHeaderFooterView *)view;
[headerIndexText.textLabel setTextColor:[UIColor whiteColor]];
}
Run Code Online (Sandbox Code Playgroud)
上面的代码在iOS6和iOS7上运行良好,并且已经生产了一段时间.但是,在iPhone5S模拟器上的iOS8上运行时,应用程序崩溃时出现以下错误:
- [UIView textLabel]:无法识别的选择器发送到实例0xeccad20
这是一种不赞成使用此标签样式的方法,还是iOS8中的错误?
我遇到过同样的问题。在以前的 iOS 版本中,如果您有自定义标题视图,则不会使用willDisplayHeaderView:forSection:自定义视图的部分来调用委托,并且类型转换是安全的。现在显然他们会为每个标头打电话给您,甚至是您的自定义标头。因此,该view参数可能是您的自定义 UIControl,而不是实际的 UITableViewHeaderFooterView。要过滤掉对您的委托的新 iOS8 调用,请按如下方式保护它:
-(void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section{
if([view isKindOfClass:[UITableViewHeaderFooterView class]]) {
UITableViewHeaderFooterView *headerIndexText = (UITableViewHeaderFooterView *)view;
[headerIndexText.textLabel setTextColor:[UIColor whiteColor]];
} else {
NSLog(@"This is the new iOS case where the delegate gets called on a custom view.");
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1519 次 |
| 最近记录: |