我使用带有神奇记录的核心数据,并尝试在表格视图中使用搜索栏过滤数据。
我写了两种方法来获取行数和单元格的名称:
-(int) dammiNumeroCercati:(NSString *)searchBar
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"nome CONTAINS [cd] %@", searchBar];
NSArray*arra = [Ricetta MR_findAllSortedBy:@"nome" ascending:YES withPredicate:predicate];
return arra.count;
}
-(NSString*) dammiNomeRicettaCercata:(NSString *)searchBar mostrataNellaCella: (int) cella
{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"nome CONTAINS [cd] %@", searchBar];
NSArray *arra = [Ricetta MR_findAllSortedBy:@"nome" ascending:YES withPredicate:predicate];
Ricetta*ctn = arra[cella];
return [NSString stringWithFormat:@"%@", ctn.nome];
}
然后我在 numberOfRowsInSection: 和 cellForRowAtIndexPath: 内调用此方法: if 循环:
if (self.mySearchBar.isFirstResponder){
// the above methods
} else {
// the normals methods to have all the data
}
有人知道我错在哪里或者我错过了什么吗?