Reputation: 7207
I am using an UITableView
for showing some data. Now when an user tap on a cell I appended a new cell just below the taped cell to show some more extra information. Everything is working fine. It's has two sections. Now if I tap on a cell of section 1 it's append a new cell as it should be. Then I do down scroll and the appended cell & it's parent cell is going out of the visible rect. And when I do up scroll it's shows back. No issue. But the problem is if I scroll up very fast it got crashed on the below line.
UITableViewCell *parentCell=[tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:[indexPath row]-1 inSection:[indexPath section]]];
In console it shows
***** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 5 beyond bounds [0 .. 4]'
If I scroll slowly it's works fine only got crashed if I do it fast. And very strange is if I do the same for section 0. It's not got crashed. Guys please help me. I already spent lot of time to figure out this but fail. Thanks in advance.
Upvotes: 0
Views: 429
Reputation: 122458
The -1
in [indexPath row]-1
is almost certainly wrong; the row is zero-based and so are your data structures (well they are if you keep your data in an NSMutableArray
or somesuch).
However this doesn't tally with the exception "5 is greater than 4", so I'm assuming you are making "+1" and "-1" adjustments here and there which is breaking your app.
I'm pretty sure you don't have to make these adjustments at all, however I cannot tell for certain without seeing more code.
Upvotes: 1