Reputation: 3821
Running Xcode 5.1 (7.1 beta) on the iPad Retina 64bit simulator, I am required to change the return type to 'double', when on a device with 7.1 beta I have to change it to 'float'. If I run the app without changing the type, the cell height is effectively 0. Has anyone else seen or had this problem before? I cannot find any information about it online.
- (float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([lastSelectedIndexPath isEqual:indexPath]) {
return 310.0;
} else {
return 120.0;
}
}
Upvotes: 0
Views: 455
Reputation: 18528
All you have to do is replace the method line from
-(float)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
//^^^^^ The return type is incorrect, the whole line needs to be replaced
with
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
This is because Apple's default delegate method for the heightForRowAtindexPath requires the use of CGFloat instead of float. You can also double check future delegate methods you may implement by going into your .h file, and right clicking on the UITableViewDelegate or UITableViewDataSource protocol to see Apple's full list of method constructions and how they should be called, used and what their return types are.
More information about using CGFloat
instead of float
in response to Wain's comment.
From the post Why to use CGFloat instead of float
"CGFloat is just a typedef for float. This provides flexibility for CGFloat to be something different down the road. Which is why using it future-proofs your code. Objective-C does this with many types, NSInteger is another example." - Jason McReary.
So Apple likes using these type-defs and encourage developers to do the same so that your code can be future proof in case the underlying architecture changes in how floats are handled.
Upvotes: 3