2010-08-29 73 views
1

我有一個分段UITableView使用字典修改代碼從教程(我目前沒有鏈接,但我可以挖掘它,如果你真的需要它)。UITableView分行問題

反正我試圖把它從列表中刪除一個項目時,我得到這個錯誤(警告:它長)

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (2) must be equal to the number of rows contained in that section before the update (2), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted). 

我種獲取的行數的信息,但我螺母肯定如何解決這個問題。

如果你想看到我的調試信息粘貼分箱,因爲它這麼久:​​

這裏是我的代碼:

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)index { 
NSDictionary *dictionary = [data objectAtIndex:index.section]; 
NSMutableArray *array = [NSMutableArray arrayWithArray:[dictionary objectForKey:@"My Wishlists"]]; 
NSString *selectedWishlist = [array objectAtIndex:index.row]; 
//now remove the item 
[array removeObjectAtIndex:index.row]; 
[data removeObjectAtIndex:index.section]; 
NSDictionary *newdictionary = [NSDictionary dictionaryWithObject:[NSArray arrayWithArray:array] forKey:@"My Wishlists"]; 
[data insertObject:newdictionary atIndex:0]; 
// [data addObject:newdictionary]; 
[mainTableView reloadData]; // tried without and with this, no difference 
[mainTableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:index] withRowAnimation:UITableViewRowAnimationTop]; 
} 

謝謝! 基督教斯圖爾特

回答

1

看起來這是你的問題:

[data insertObject:newdictionary atIndex:0]; 

從文檔的NSMutableArray中的insertObject:atIndex:

討論如果指數已經 佔用,在對象索引和 超越通過添加1至 他們的指數騰出空間。

嘗試使用replaceObjectAtIndex:withObject:代替。