Implement heightForRowIndexPath: in iOS 7, but remove it in iOS 8 using compile-time macro

核能气质少年 提交于 2019-12-10 09:42:19

问题


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?


回答1:


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.
  }

}


来源:https://stackoverflow.com/questions/25965039/implement-heightforrowindexpath-in-ios-7-but-remove-it-in-ios-8-using-compile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!