【发布时间】:2011-11-29 01:59:01
【问题描述】:
我有这段代码可以在我的应用程序的根视图控制器中的表视图中添加一行:
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
NSArray *myArray = [NSArray arrayWithObject:indexPath];
NSLog(@"count:%d", [myArray count]);
[self.tableView insertRowsAtIndexPaths:myArray withRowAnimation:UITableViewRowAnimationFade];
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
当它与模拟器一起运行时,我得到以下输出:
count:1
* 由于未捕获的异常“NSRangeException”而终止应用程序,原因:“* -[NSMutableArray objectAtIndex:]:空数组的索引 0 超出范围”
这发生在[self.tableView insertRowsAtIndexPaths:myArray withRowAnimation:UITableViewRowAnimationFade]; 行,但NSLog 语句显示调用myArray 的NSArray 不为空。我错过了什么吗?有没有人遇到过这种情况?
【问题讨论】:
标签: objective-c ios cocoa-touch nsarray