我想在 iOS 8 中实现新的自动调整大小的表格 View 单元格,同时在 iOS 7 中保持对 heightForRowAtIndexPath:
的支持。问题是我必须删除方法覆盖 heightForRowAtIndexPath:
适用于 iOS 8,但适用于 iOS 7。是否有一些编译时宏可用于完成此操作?
最佳答案
您不能使用编译时宏,因为这是运行时决定的。相反,对于 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.
}
}
关于uitableview - 实现 heightForRowIndexPath : in iOS 7, 但在 iOS 8 中使用编译时宏删除它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25965039/