1

I can't solve the mystery of my NSRangeException.

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_countyList count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"Inside masterview cellforrowatindexpath.\n");

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    // Configure the cell...
    cell.textLabel.text = [_countyList objectAtIndex:indexPath.row];

    return cell;
}

The exception is thrown when I have numberOfSectionsInTableView return 1 (there should be 1 section), but when I return 0 sections it does not throw an exception (it also does not display my data). When the code runs, it never calls cellForRowAtIndexPath. The debugger takes me to the main function and I cannot see where I am accessing a NSArray for the life of me.
Any help or debugging tips would be greatly appreciated...

athspk
  • 6,722
  • 7
  • 37
  • 51
Destron
  • 414
  • 2
  • 9
  • You can set an exception breakpoint to debug this more easily. Simply go to the breakpoints tab in the navigator (Cmd+6) and select "Add Exception Breakpoint" in the menu of the + button at the bottom. – omz Dec 13 '11 at 04:43
  • Thanks omz. I already had an exception breakpoint setup but it was breaking in the main() function. VinceBurn correctly guessed my problem. – Destron Dec 13 '11 at 05:37

1 Answers1

2

If you are using storyboard check this post.

iOS Xcode 4.2 Master-Detail Application Template Throwing NSRangeException

The problem you are describing look similar to that one.

Community
  • 1
  • 1
Vincent Bernier
  • 8,674
  • 4
  • 35
  • 40
  • Wow, thank you! That was exactly my problem. I guess the "static content" in storyboard cells are if you only want to set up the content... in the storyboard. – Destron Dec 13 '11 at 05:36
  • 2
    @NicholasMarrone: You may want to consider accepting this answer. – Dov Dec 13 '11 at 21:15