- (void)addPlace {
//set up add controller
PlacesAddViewController *addController = [[PlacesAddViewController alloc] initWithStyle:UITableViewStyleGrouped];
addController.delegate = self;
// create new place and assign it to add controller
Place *newPlace = [NSEntityDescription insertNewObjectForEntityForName:@"Place" inManagedObjectContext:self.managedObjectContext];
addController.place = newPlace;
// set up navigation controller
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:addController];
[self presentModalViewController:navigationController animated:YES];
// release controllers
[navigationController release];
[addController release];
}
方法insertNewObjectForEntityForName正確返回廣場的新實例,當我嘗試最初加入的地方,但是當我從列表中刪除的地方,然後按「+」這種方法又稱爲這次insertNewObjectForEntityForName返回剛刪除的地方。NSEntityDescription insertNewObjectForEntityForName返回NSManagedObject剛剛刪除
任何人都可以給我一些想法,發生了什麼?我知道這個方法返回一個自動釋放對象 - 不知道這與它有什麼關係。
更新:我認爲這是因爲在添加視圖控制器顯示之前,您可以看到第一行中的表視圖控制器頂部插入的新對象。當顯示添加視圖控制器時,新對象確實是一個新實例。另外,如果我保存這個對象,它會正確地用正確的信息替換表視圖控制器中的行。所以也許這與我下面的表格視圖有關。啊,我只是想出了答案,並回答了我自己的問題。我的cellForRowAtIndexPath使用重複使用的單元格,並且信息顯示最新的單元格被刪除。我已經解決了這個問題。不過謝謝你的保證,它不是上面的代碼。