1

I have looked around on this and this error seems to get tacked on to completely different issues. Here is my code clip, tell me if you might need more. This is setting the size on the last cell of a table using using UITableView.

- (CGFloat)tableView:(UITableView *)tableView
 heightForRowAtIndexPath:(NSIndexPath *)indexPath
 {
     int returnValue = 44;
     int numRows = [tableView numberOfRowsInSection:[indexPath section]];
    if (!([indexPath row] ==  numRows - 1)) {
        returnValue = 60;
    }
    return returnValue;
 }

I have commented out all of the lines on in the code to find that the [tableView numberOfRowsInSection:[indexPath section]] throws up the error. Any ideas?

Edit: It looks like every time you call tableView it redraws all of the cells which calls this method which calls this method ad nauseum. I found this in the documentation for the method:

"Every time a table view is displayed, it calls tableView:heightForRowAtIndexPath: on the delegate for each of its rows, which can result in a significant performance problem with table views having a large number of rows (approximately 1000 or more)."

Does this mean I can't call these methods?

Edit 2: Found my answer here

Community
  • 1
  • 1
Evan Richards
  • 73
  • 1
  • 10
  • 1
    What is the complete error message and the backtrace? If you have not already add the Exception breakpoint to get a better error info. – zaph Dec 31 '12 at 21:01
  • Could it be that you're returning the wrong number of sections from `numberOfSectionsInTableView:`? This would result in you going outside the bounds of the table. – Peter Dec 31 '12 at 21:04
  • The complete message is `Thread 1: EXC_BAD_ACCESS(code=2, address=0xbf7fffc)`. My numberOfSectionsInTableView is just `return 2`. – Evan Richards Dec 31 '12 at 22:04
  • I think `numberOfRowsInSection:` is the problem here, not `numberOfSectionsInTableView:`, since it's the former that appears in the crash. What does _that_ do? – abarnert Dec 31 '12 at 23:02
  • its quite a bit more complicated but i am positive that part works. I threw in an `NSLog(@"row: %i, section: %i", [indexPath row], [indexPath section]);` before the method that was messing up. It just prints out `row: 0, section: 1` over and over several hundred times. – Evan Richards Dec 31 '12 at 23:23

3 Answers3

0

That error always indicates one thing: you're application has attempted to access memory that it does not have access to. That usually translates into your application trying to dereference a bad pointer. In this case the bad pointer is either tableView or indexPath. Check to see if they are NULL or if they've already been freed (turning on NSZombies can help with seeing if they're already freed).

user1118321
  • 25,567
  • 4
  • 55
  • 86
  • So i threw in two NSLog descriptions and it came out with an address for both on every pass of the method call. `tableView: ; layer = ; contentOffset: {0, 0}>`. – Evan Richards Dec 31 '12 at 22:07
  • And does it crash in these cases? If so, maybe something in the table view or index path is bad? – user1118321 Jan 01 '13 at 04:34
0

Do you have any property declared tableView in the .h file. If so you can try modifying the name of the local UITableView variable in the function. Other than that I think Peter might be right about the numberOfSectionsInTableView: return value.

ShaluRaj
  • 67
  • 6
0

Hope the problem in your code is

int numRows = [tableView numberOfRowsInSection:[indexPath section]];

Hope to set number of rows in section you may have some array whose count you are returning os some static value. So to get the number of rows use that array count or that static value. Hope it may solve your problem.

Bhavin Ramani
  • 3,221
  • 5
  • 30
  • 41
Exploring
  • 925
  • 6
  • 18