IOS5: how to throw an exception for the rectForRowAtIndexPath method

An exception:

error request for invalid pointer path

the code:

CGRect rect = [tableView rectForRowAtIndexPath:[NSIndexPath indexPathForRow:i inSection:0]];

Fix:

if ([tableView numberOfRowsInSection:0] <= i) {
    return;
}

Perhaps there is a better way

+5
source share
1 answer

Normally, rectForRowAtIndexPath can treat invalid indexPaths as document states, but in iOS 7.1, it incorrectly processes an invalid index. Thus, passing to nil will fail and receive an error message:

error request if the pointer path is incorrect ({length = 2, path = 0 - 0})

In short, manually performing a nil check is necessary for rectForRowAtIndexPath.

+3
source

All Articles