2011-08-18 54 views
0

我正在使用類「SampleClass」的NSManagedObjects數組填充TableViewController。儘管fetched數組中的對象數量正確返回(即,如果該表要顯示59個對象,則會創建59行),但單元格的其他參數會顯示「glitchy」。由核心數據填充的表格無法正確顯示

例如,應該有一個標題由object.name設置,「null」直到您單擊單元格,選擇另一個單元格,然後返回到初始單元格。

我已經嘗試`[tableview reloadData]'在視圖中將出現,並且它仍然需要太長時間來加載數據。有沒有更好的方式來填補在相應的單元格的:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 

    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 

} 

Class *classObject = [dataArray objectAtIndex:indexPath.row]; 

cell.textLabel.text = [classObject name]..... 

其中來自coreData通話

注dataArray中的指向NSMutableFetchedArray:模擬器失誤填充更多的細胞比實際的iPad。一旦另一個選項卡中選中然而,所有的細胞正確顯示當您返回到tab.`

回答

2

你可能想看看NSFetchedResultsController

http://developer.apple.com/library/iOS/ipad/#documentation/CoreData/Reference/NSFetchedResultsController_Class/Reference/Reference.html

這是這是專門指一類特殊的用來自核心數據查詢的結果填充表格。

在過去,當使用核心數據時,我總是使用這個類而不是其他方法。

+0

我只是注意到要小心NSFetchedResultsController,如果你的目標是低於4.0的SDK,因爲它有很多問題。 –