【问题标题】:Implement heightForRowIndexPath: in iOS 7, but remove it in iOS 8 using compile-time macro在 iOS 7 中实现 heightForRowIndexPath:,但在 iOS 8 中使用编译时宏将其删除
【发布时间】:2014-11-15 21:15:07
【问题描述】:
我想在 iOS 8 中实现新的自动调整大小的表格视图单元格,同时在 iOS 7 中保持对 heightForRowAtIndexPath: 的支持。问题是我必须为 iOS 8 删除方法覆盖 heightForRowAtIndexPath:,但是保留在 iOS 7 中。是否可以使用一些编译时宏来完成此操作?
【问题讨论】:
标签:
uitableview
ios7
macros
ios8
heightforrowatindexpath
【解决方案1】:
您不能使用编译时宏,因为这是运行时的决定。相反,对于 iOS 8,您可以只返回 UITableViewAutomaticDimension,如果没有,则返回您计算出的高度值。
#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.
}
}