来自UITableViewController的NSRangeException

时间:2011-12-13 04:37:19

标签: objective-c ios nsrangeexception

我无法解开我的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;
}

当我numberOfSectionsInTableView返回1(应该有1个部分)时抛出异常,但是当我返回0个部分时它不会抛出异常(它也不会显示我的数据)。代码运行时,它永远不会调用cellForRowAtIndexPath。调试器将我带到主要功能,在我的生命中我无法看到我在哪里访问NSArray。
任何帮助或调试技巧将不胜感激......

1 个答案:

答案 0 :(得分:2)

如果您使用的是故事板,请查看此帖子。

iOS Xcode 4.2 Master-Detail Application Template Throwing NSRangeException

您所描述的问题与该问题类似。

相关问题