UITableView Delegate Method

user2199783

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!

sha

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Delegate method not being called?

From Dev

Looking for subviewsDidChange delegate method

From Dev

Generic Method assigned to Delegate

From Dev

UITableView delegate/datasource default value

From Dev

UIPageViewController delegate method not called

From Dev

Enums in delegate method declaration

From Dev

No overload for method matches delegate?

From Dev

UITableview delegate and datasource called twice

From Dev

UITableView Delegate in Sub Viewcontroller

From Dev

Custom delegate method in Swift

From Dev

Delegate Method is not called in Swift?

From Dev

willDisplayCell delegate method Swift

From Dev

In UITableView, what's the delegate for "visibleCells"?

From Dev

UITableView delegate using extensions swift

From Dev

Logging for each method in "delegate"

From Dev

What is this delegate method doing?

From Dev

Delegate method is not called (is nil)

From Dev

set delegate and dataSource to UITableView

From Dev

Generic Method assigned to Delegate

From Dev

UITableView delegate/datasource default value

From Dev

UIPageViewController delegate method not called

From Dev

UITableview Delegate method calls before json method

From Dev

Can a property of a UITableView be the UITableView Delegate and DataSource

From Dev

UITableView is not calling my cell delegate

From Dev

UITableView delegate is not getting called

From Dev

NSObject as delegate for UITableView

From Dev

Add new method to UITableView delegate

From Dev

Handling delegate of UItextfield in UItableView

From Dev

UITableView Delegate is not called