我正在iphone應用中實施搜索欄。我有工人名單,每個都有屬性:名字,姓氏,公司。表格視圖的部分設置爲公司屬性。NSFetchedResultsController錯誤:在索引X處的抓取對象的亂序部分名稱爲Y.對象必須按部分名稱排序'
搜索時我沒設置斷言:
NSPredicate *predicate =[NSPredicate predicateWithFormat:@"firstName contains[cd] %@", searchBar.text];
,我得到錯誤:
NSFetchedResultsController ERROR: The fetched object at index 3 has an out of order section name 'company2. Objects must be sorted by section name'
時,我有sortDescriptor:
,當我改變它NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"lastName" ascending:YES selector:@selector(caseInsensitiveCompare:)];
我沒有通知到
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"firstName"` ascending:YES selector:@selector(caseInsensitiveCompare:)];
現在搜索正常工作,沒有錯誤。 initWithKey參數是否必須在謂詞中匹配屬性名稱?我不明白。
你在使用NSFetchedResultsController嗎? – TechZen 2011-06-07 15:46:33
是的,我正在使用NSFetchedResultsController。 – alhcr 2011-06-07 16:07:55