uitableview - 实现 heightForRowIndexPath : in iOS 7, 但在 iOS 8 中使用编译时宏删除它

标签 uitableview ios7 macros ios8 heightforrowatindexpath

我想在 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/

相关文章:

swift: 将 navigationController 添加到 viewController 后,tableView 高度不适合屏幕

swift - cell.textLabel.text 未附加

ios - iOS 7 API 和 iOS 6 API 之间的差异

带有空字符串的 c 标记粘贴(连接)

ios - NSFetchedResultsController - 不调用委托(delegate)函数

ios - 如何在 UITableView 中创建刷新按钮

ios - 当模态呈现另一个 View Controller 时,如何完全关闭 View Controller 的所有后台工作

ios - 在ios标签栏中禁用编辑按钮

c - 表达式中大括号组的 ISO C 等价物

loops - 在SAS中循环字符值