2009-11-15 7 views
0

그래서 내 앱에서 검색 창을 구현하는 데 문제가 있습니다.UISearchBar 메서드로 도움말

메서드는 필터링 된 항목을 찾지 만 어떤 이유로 내 tableview에 표시되지 않습니다. 나는 filteredListContentArray에 객체를 추가하는 것과 관련이 있다고 생각한다.

이 기능을 사용하려면 어떤 개체를 추가해야합니까?

마지막 NSLog는 (널)마다,하지만 위의 NSLog를 읽
{ 
[self.filteredListContent removeAllObjects]; // First clear the filtered array. 
for (NSDictionary *dictionary in tableDataSource) 
{ 

    NSString *testString = [dictionary valueForKey:@"Title"]; 
    NSLog(@"String list to be Searched is %@", testString); 
    //NSLog(@"Contents of list are %@", testString); 
    NSComparisonResult result = [testString compare:searchText options:(NSCaseInsensitiveSearch|NSDiacriticInsensitiveSearch) range:NSMakeRange(0, [searchText length])]; 
    //NSObject *filteredObject = [dictionary objectForKey:@"Title"]; 
    if (result == NSOrderedSame) 

    { 
     NSLog(@":-)"); 
     NSLog(@"Resulted object is %@", [dictionary valueForKey:@"Title"]); 
     [self.filteredListContent addObject:dictionary]; 
    } 
    else 
    { 
     NSLog(@":-("); 
    } 
} 


NSLog(@"Contents of Filtered list are %@", self.filteredListContent);} 

항상 정확한 필터링 항목을 보여줍니다

여기 내 코드입니다.

답변

0

여기서 filteredListContent에 대한 메모리를 할당합니까? 그리고 거기에 tableDataSource 배열입니다. filteredListContent 또는 tableFataSource 배열에서 테이블을 채우시겠습니까? 또한 당신은 콘솔에 인쇄하려고 할 수 있습니다 [filteredListContent description];

+0

와우. 샘플에서 한 줄의 코드가 누락되었습니다. self.filteredListContent = [NSMutableArray arrayWithCapacity : [self.tableDataSource count]]; 정말 고마워! – monotreme