每当我将视图中的 NSString 返回插入 UITableView 的数据源时,当放置插入新单元格的调用时,程序就会崩溃。下面是代码:
- (void)insertTableObject:(NSString *)thing
{
if (!locations) locations = [[NSMutableArray alloc] init];
[locations addObject:[NSString stringWithFormat:@"%@", thing]];
NSLog(@"%@", locations);
self.tableContents = [[NSMutableDictionary alloc] initWithObjectsAndKeys:locations,@"", nil];
self.sortedKeys =[[self.tableContents allKeys] sortedArrayUsingSelector:@selector(compare:)];
[self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:([locations count]-1) inSection:0]] withRowAnimation:UITableViewRowAnimationAutomatic];
}
下面是打印出来的数组,以及随之而来的错误:
2013-03-23 15:06:32.433 XXX[9149:907] (
"D.C",
la
)
2013-03-23 15:06:32.439 XXX[9149:907] *** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 1 beyond bounds [0 .. 0]'
*** First throw call stack:
(0x320852a3 0x39f1b97f 0x31fd0b75 0xc05bd 0x33ed854d 0x33ec9685 0x33ec5d55 0x33ec4d27 0x33ec1bf9 0x33ff6b27 0xbeceb 0xf6413 0x33f780c5 0x33f78077 0x33f78055 0x33f7790b 0x33f77e01 0x33ea05f1 0x33e8d801 0x33e8d11b 0x35b815a3 0x35b811d3 0x3205a173 0x3205a117 0x32058f99 0x31fcbebd 0x31fcbd49 0x35b802eb 0x33ee1301 0xb701b 0xb6f70)
libc++abi.dylib: terminate called throwing an exception
“la”打印时没有引号是一个问题吗?系统可能看不到该条目吗?