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?
            Asked
            
        
        
            Active
            
        
            Viewed 483 times
        
    3
            
            
         
    
    
        Erich
        
- 2,509
- 2
- 21
- 24
- 
                    I had the exact same problem. Here is my solution: [http://stackoverflow.com/questions/26022113/how-to-override-a-method-only-if-ios-version-earlier-thn-8/26022467#26022467][1] [1]: http://stackoverflow.com/questions/26022113/how-to-override-a-method-only-if-ios-version-earlier-thn-8/26022467#26022467 – amirfl Sep 24 '14 at 16:59
1 Answers
3
            
            
        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.
  }
}
 
    
    
        batu
        
- 645
- 3
- 10