I'm trying to adjust the height of only the last row of a table view. I seem to be encountering some sort of recursive loop when trying to find the index of the last row. In my heightForRowAtIndexPath:
method I have the following:
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
CGFloat height = 60;
NSInteger lastSectionIndex = [tableView numberOfSections] - 1;
NSInteger lastRowIndex = [tableView numberOfRowsInSection:lastSectionIndex] - 1; // BLOWS UP!
if ((indexPath.section == lastSectionIndex) && (indexPath.row == lastRowIndex)) {
height = 44;
}
return height;
}
If I tweak the code a just a little, it works.
NSInteger lastRowIndex = [self tableView:tableView numberOfRowsInSection:lastSectionIndex] - 1; // WORKS!
Can any Objective-C/iOS gurus shine some light as to what's going on here? Why does one syntax work over the other? Aren't they the exact same method?
You can check out the code here for context: https://github.com/phungkytown/chapter8_gold
Any help is greatly appreciated!
I would advise not to go the tableView delegates for obtaining number of sections and number of rows, but get this information directly from your datasource.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments