在iOS 7中实现heightForRowIndexPath:但是在iOS 8中使用编译时宏删除它 [英] Implement heightForRowIndexPath: in iOS 7, but remove it in iOS 8 using compile-time macro
问题描述
我想在iOS 8中实现新的自动调整大小表视图单元格,同时在iOS 7中保持对 heightForRowAtIndexPath:
的支持。问题是我必须为iOS 8删除方法覆盖 heightForRowAtIndexPath:
,但为iOS 7保留它。是否有一些编译时宏可以实现这一点?
I'd like to implement the new auto-resizing table view cells in iOS 8, while maintaining support for heightForRowAtIndexPath:
in iOS 7. The problem is I have to remove the method override heightForRowAtIndexPath:
for iOS 8, but keep in it for iOS 7. Is there some compile-time macro to use that will accomplish this?
推荐答案
您不能使用编译时宏,因为这是运行时决定。相反,你可以为iOS 8返回 UITableViewAutomaticDimension
,如果没有,则返回你计算的身高值。
You can not use a compile time macro because this is a run time decision. Instead, you can just return UITableViewAutomaticDimension
for iOS 8 and if not, return your calculated height value.
#define IS_IOS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
-(CGFloat) tableView: (UITableView * ) tableView heightForRowAtIndexPath: (NSIndexPath * ) indexPath {
if (IS_IOS_8_OR_LATER)
return UITableViewAutomaticDimension;
else {
//Your iOS 7 code here.
}
}
这篇关于在iOS 7中实现heightForRowIndexPath:但是在iOS 8中使用编译时宏删除它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!