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?
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