2013-07-01 3 views
0

핵심 데이터를 마법 기록과 함께 사용하며 표보기에서 검색 막대를 사용하여 데이터를 필터링하려고합니다. 및 cellForRowAtIndexPath :핵심 데이터 프로젝트의 검색 창

-(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 내부 메서드를 호출 :

나는 셀의 행의 수와 이름을 얻기 위해 두 가지 방법을 쓰기

if (self.mySearchBar.isFirstResponder){ 

// the above methods 

} else { 
// the normals methods to have all the data 
} 
: 내부 순환 경우

누군가 내가 잘못했는지 또는 한 가지를 놓치면 알 수 있습니까?

+0

무엇이 문제입니까? 위의 메서드를 어떻게 호출합니까? 무슨 인자가 지나가는 것처럼? – govi

+0

효과가 있더라도 'MR_findAllSortedBy'를 반복 호출하는 것은 매우 효과적이지 않습니다. NSFetchedResultsController를 봐야합니다. –

+0

@ govi 문제는 검색 창이 작동하지 않는다는 것입니다. – Totka

답변

0

searchBar은 보통 문자열이 아니고 UISearchBar입니다.

searchBar.text을 사용하고 해당 방법으로 처리해야합니다.

또한 테이블 뷰의 데이터 소스 메서드에서 어떤 테이블 뷰가 콜백을 일으키는 지 확인한 다음 올바른 카운트/문자열을 반환해야합니다. 일반적으로 두 테이블 (원본 테이블보기 및 검색 결과 테이블보기)에 대한 포인터를 비교하여 검사합니다.

-(NSUInteger)tableView:(UITableView*)tableView 
     numberOfRowsInSection:(NSUInteger)section { 

    if (tableView == _tableView) { 
     // return the usual row count 
    } 
    return [self dammiNumeroCercati:_searchBar.text]; 
} 
관련 문제