我有這樣的應用程序(接觸式的),可以在其中添加實例表視圖被加載時,它工作正常添加的對象,到列表中崩潰。該列表將它們完美地呈現爲詳細視圖。我可以調用「添加項目」(A與TableView中的UIViewController它)鑑於很多次我想在我的MasterViewController(該UITableViewController中,導航控制器的rootControler)。的TableView試圖通過不同的類
當我看到這個工作,並希望擴大我的應用程序的功能,讓用戶編輯列表中的當前對象,我在詳細視圖的導航控制器中添加了一個「編輯」按鈕,這個UiBarButton觸發器一種嘗試加載用於在表格視圖中添加項目的相同「添加項目」視圖的方法。這是奇怪的事情開始發生的地方。
如果我運行應用程序,並在列表中點擊查看現有的對象上,我成功邁出的詳細視圖。如果我然後點擊「編輯」按鈕,它正在編輯的對象的數據很好的「添加項目」視圖負荷。然後,我可以取消/保存/關閉那些「添加項目」視圖許多次,只要我保持從詳細信息視圖調用它。如果我然後回到列表視圖並嘗試添加項目,則應用程序崩潰。
如果我啓動應用程序,以及任何其他事情之前,我從加載主列表視圖「添加項目」,視圖將完全加載,因爲我想我完全可以添加對象多次。如果我然後轉到詳細視圖並嘗試編輯對象,則應用程序崩潰。
簡單的說(如果你懶得看以上):應用程序崩潰,每當我嘗試從不同的控制器加載「添加項目」視圖,而不是第一次加載它。
這裏的崩潰日誌:
*** Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:],
/SourceCache/UIKit_Sim/UIKit-1914.84/UITableView.m:6061
2012-03-26 21:22:49.087 Vex Try 5[2749:f803] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason:
'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'
*** First throw call stack: ...
顯然,它會嘗試加載第二次,cellForRowAtIndexPath
返回一個怪異的細胞。
以下是我把它在列表視圖:
- (void)insertNewObject:(id)sender
{
if (!_objects) {
_objects = [[NSMutableArray alloc] init];
}
BIDVexTeam *newTeam = [[BIDVexTeam alloc] init];
[_objects insertObject:newTeam atIndex:0];
if (!self.addNew) {
self.addNew = [[BIDEditViewController alloc] init];
}
if (!self.editNavController) {
self.editNavController = [[UINavigationController alloc] initWithRootViewController:self.addNew];
}
addNew.title = @"Add New";
addNew.team = newTeam;
addNew.parent = self;
[self presentModalViewController:self.editNavController animated:YES];
}
這裏就是我把它從詳細信息視圖:
- (IBAction)editTeam:(id)sender {
if (!self.editView) {
self.editView = [[BIDEditViewController alloc] initWithNibName:@"BIDEditViewController" bundle:[NSBundle mainBundle]];
}
if (!self.editNavController) {
self.editNavController = [[UINavigationController alloc] initWithRootViewController:self.editView];
}
editView.title = [NSString stringWithFormat:@"Edit %@", detailTeam.number];
self.editView.team = self.detailTeam;
[self presentModalViewController:editNavController animated:YES];
}
編輯:這是我的cellForRowAtIndexPath方法...沒有粘貼在這裏,因爲它很長,以及我想要實現的屏幕截圖:
http://www.clubpenguinaccess.com/extra/cellforrow-method.rtf
screenshot http://www.clubpenguinaccess.com/extra/app-screenshot.png
已發佈。它太長了,所以我上傳了它的rtf格式(所以它會保持Xcode的顏色) – 2012-03-27 05:09:14