2011-11-10 21 views
0
request.fetchLimit = 100; 
request.fetchBatchSize = 100; 

是否真的使用該函數來限制tableView中有多少行與NSFetchedResultsControllerDelegate?使用NSFetchedResultController如何確保只顯示100行

但問題是..有時表格會顯示100多行,但是當我改變頁面並返回到表格時,表格會顯示100行,它怎麼可能?我不希望該表可以顯示超過100個。

謝謝你的高級。

另一種方法是做

是更新

id <NSFetchedResultsSectionInfo> sectionInfo = [[self.FetchController sections] objectAtIndex:section]; 
    CalledRowCountingNotYetCallRowForSection=true; 
    [self.tableViewA setBounces:YES]; 


    if([sectionInfo numberOfObjects]>100){ 
     //[Timer searchCriteriaChanged]; 
     CLog(@"Something Wrong This NumberOfRow: %d", [sectionInfo numberOfObjects]); 
    } 
    else{ 
    } 
    return [sectionInfo numberOfObjects]; 

使得當numberOfObjects大於100,則行數變爲100。然而,與

干擾
- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject 

那麼你怎麼做呢?

回答

0

你可以通過重寫numberOfSectionsInTableViewnumberOfRowsInSection您的表視圖的數據源的功能,分別返回1和100,限制了可用行的數量。

您是否使用SQLStore作爲您的表的基礎?根據蘋果文檔(http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/CoreDataFramework/Classes/NSFetchRequest_Class/NSFetchRequest.html#//apple_ref/doc/c_ref/NSFetchRequest),fetchLimit僅適用於SQL存儲。

+0

如果我這樣做,我會崩潰。 –

+0

它干擾更新。 –