2013-03-23 34 views
0

每當我從視圖中插入一個NSString返回到UITableView的數據源時,當插入新單元的調用被放置時,程序崩潰。下面是代碼:插入到UITableView DataSource中的字符串沒有被插入

- (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」不帶引號的打印問題?系統可能沒有看到該條目嗎?

+0

你可以請你的'tableView:cellForRowAtIndexPath:'代碼? – 2013-03-23 20:13:08

+0

同時顯示你的'numberOfSections'和'numberOfRowsForSection'方法。 – rmaddy 2013-03-23 22:10:53

回答

0

我最終解決了這個問題。我有細胞的細節意見,所以當它將繪製detailView索引,它不存在。我在原始文章中爲函數添加了一條簡單的線條,以將其他值添加到detailView數組中。