Strange jump in cellForRowAtIndexPath to another return statement
I have this in my tableView:cellForRowAtIndexPath:
if (condition) {
// make a custom cell
return cell; // line number 240
}
else {
// make another kind of cell
return cell; // line number 256
}
I got a EXC_BAD_ACCESS, so I fired up the开发者_JAVA百科 debugger and set a breakpoint, stepping through the code line by line.
When I stepped forward "step over" from line number 256 it went directly to line 240, i.e. into another branch of the if
statement. How is that possible???
Thanks a lot for your help,
SaschaI think I found the solution. The view controller with the table view is also the delegate of a background web loading thread. Apparently the debugger can only step through one thread at a time. The delegate routine did indeed call a scrollToRowAtIndexPath:
without checking the above condition
.
Still, I find the behavior of the debugger a bit puzzling.
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
will get called x times, where x = number of rows.
So I think your problem is that your (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
doesn't return a correct value, and very likely a value that's greater than where you're pulling data from.
i.e. If you have a array of size 3, but trying to make the 4th row cell.
This method calls itself the same number of times as the number of rows returned in the numberOfRowsInSection
method and each time a cell is nil. Most likely, the control went to the next row to allocate the UITableViewCell
for it, and at that time, I am guessing that the if
condition got satisfied.
Step Over is the same as Step Into, except that when it reaches a call for another procedure, it will not step into the procedure. The procedure will run, and you will be brought to the next statement in the current procedure.
so step over get the next statement and your cellForRowAtIndexPath call numberOfRow times. so in some iteration your if condition becomes true and goes to your line no 240
精彩评论