我也有这个问题,看这里:
1)我们需要创建宏
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
2) 比需要在 viewWillAppear 中检查版本
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
if (![self.p_tableView respondsToSelector:@selector(tableView:heightForRowAtIndexPath:)])
{
self.p_tableView.rowHeight = UITableViewAutomaticDimension;
self.p_tableView.estimatedRowHeight = 100.0f;
}
}
3)我们需要重写responseToSelector方法,这种方式需要更少的资源消耗,因为我们不需要为每一行调用heightForRow
- (BOOL)respondsToSelector:(SEL)selector
{
static BOOL useSelector;
static dispatch_once_t predicate = 0;
dispatch_once(&predicate, ^{
useSelector = SYSTEM_VERSION_LESS_THAN(@"8.0");
});
if (selector == @selector(tableView:heightForRowAtIndexPath:))
{
return useSelector;
}
return [super respondsToSelector:selector];
}
希望能帮助到你
通过