我在一個應用程序中有2個控制器,因爲我正在嘗試這些不同的設置。UITableViewController vs UITableView
一個是UITableViewController,它的方式我明白委託和數據源是從超類繪製的。
現在按照這個理論,我現在也有一個UIViewController和一個UITableView,並在頭文件中聲明瞭數據源和委託。
到目前爲止好:-)
現在,這是位我不明白:
在實現文件中我可以使用的tableView指針鏈接的數據,但我使用的核心數據和我有這樣一段代碼除其他:
- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
{
[self.tableView beginUpdates];
}
這和5其他情況下給出的UIViewController的一個錯誤,如果我不設置一個
IBOutlet UITableView *tableView;
當然是:-)
合成的,但如果我聲明這的tableView我得到一個警告就行了雙了,說這個:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
,因爲它也聲明瞭的tableView。
所以我有2個問題:
1)爲什麼我設置IBOutlet中,如果我設置了一個UITableViewDatasource和代表? 2)如果我給UITableViewCell一個不同的指針名稱 - 比如tableView2,爲什麼我在編輯數據時看不到更改,但只能在重新啓動應用程序後看到結果?
MasterViewController,它是UITableViewController沒有這個選項。
乾杯傑夫
---添加圖像----
要進入編輯模式,我有這樣的代碼在viewDidLoad中
self.navigationItem.leftBarButtonItem = self.editButtonItem;
,我使用此代碼動作需要做什麼:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{ 如果(editingStyle == UITableViewCellEditingStyleDelete){ 的NSManagedObjectContext *上下文= [self.fetchedResultsController managedObjectContext]; [context deleteObject:[self。fetchedResultsController objectAtIndexPath:indexPath]];
NSError *error = nil;
if (![context save:&error]) {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
}
}
現在+選項工作,但我只看到結果後,我重新啓動應用程序。我可以輕掃並刪除,但它不會在應用程序的同一個實例中進行動畫生活。
嗨,感謝您的答覆1)我已經宣佈伊娃,然後設置一個屬性它匹配。 2)我想簡化問題,如果我在頭文件中設置TableView委託和數據源,爲什麼不與tableView參數一起來? 3)我已經嘗試過使用_tableView方法進行合成,但是與將「cellForRowAtIndexPath:」更改爲tableView2的效果相同。 4)當我添加和編輯UITableViewController時,結果動畫,例如刪除標誌出現在顯示中,當我重命名View Controller中的UITableView時,這種情況不會發生。 – 2012-04-17 09:24:53
對不起,這是一個很長的評論,只是試圖用我的解釋澄清你的問題;-) – 2012-04-17 09:25:33
你可能需要在你的問題中包含更多的代碼。 1)不要這樣做,如我所建議的,去掉伊娃的聲明。 2)我不知道你是什麼意思,認爲顯示相關的代碼3)你需要包括你現在的代碼4)見3)。你如何將視圖控制器連接到表視圖,以及如何將表視圖的數據源和委託連接到視圖控制器? – jrturton 2012-04-17 09:29:27