2013-02-12 4 views
0

올바르게 설정했는지 확신 할 수 없습니다. 나는 SearchDisplayController과 검색 창을 가지고있다.NSOperation으로 TableView 데이터가 업데이트되지 않습니다.

UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 150, 44)]; 
    self.SearchEntry = searchBar; 
    self.SearchEntry.tintColor = DARKGRAY_COLOR; 
    self.SearchEntry.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin; 
    self.SearchEntry.delegate = self; 
    UISearchDisplayController *searchDisplayCtlr = [[UISearchDisplayController alloc] initWithSearchBar:_searchEntry contentsController:self]; 
    self.SearchController = searchDisplayCtlr; 

이러한 것들은 UIToolbar 안에 있습니다. 데이터베이스에 특정 값을 쿼리하는 데 약간의 시간이 걸릴 수 있으므로 코드를 빼서 NSOperation 하위 클래스에 넣었습니다. 끝에서, 그것은 실제 데이터를 업데이트 할 대리인을 통해의 ViewController를 다시 호출하여 실제 입력 내 검색 창에 갈 때 그래서

[self.searchOperationDelegate searchDidFinishWithResults:self.searchResults]; 

을, 나는 이렇게 : 나는 기본적으로 취소하고

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText 
{ 
    if (_queue.operationCount > 0) { 
     [_queue cancelAllOperations]; 
    } 

    SearchOperation *search = [[SearchOperation alloc] initWithSearchText:searchText]; 
    search.searchOperationDelegate = self; 
    [self.queue addOperation:search]; 
} 

이전 검색 및 현재 searchText 문자열에있는 내용 만 검색합니다.

그리고 내의 ViewController

- (void)searchDidFinishWithResults:(NSArray *)results { 
     NSLog(@"resultsList: %i", [results count]); 
    [self performSelectorOnMainThread:@selector(setResultsList:) withObject:results waitUntilDone:YES]; 
// [self.searchDisplayController.searchResultsTableView reloadData]; 
} 

내 대리인 콜백 메소드에

나는 또한 내에있는 [결과 계산] 얼마나 많은 항목을 확인하는 내 cellForRowAtIndexPath 방법에 로그가 있습니다. 내가 볼 때 기본적으로 cellForRowAtIndexPath을 여러 번 호출합니다 (우리가 검색하는 내용에 따라 1000-3000이라고 말합니다). 그런 다음 내 searchDidFinishWithResults: 메서드에서 1 항목을 얻습니다. 호출 된 것은 항상 cellForRowAtIndexPath이고,이 searchDidFinishWithResults: 메서드입니다. 따라서 모델을 업데이트 한 후에 테이블이 다시 업데이트되지 않고 이유가 확실하지 않습니다. reloadData을 수동으로 호출 할 수 있다고 생각했지만 그 결과는 똑같습니다.

resultsList: 2909 (I type in one key, and only this gets logged) 
tableView:cellForRowAtIndexPath:] 2909 (my second key in the search bar, this gets logged) 
tableView:cellForRowAtIndexPath:] 2909 
tableView:cellForRowAtIndexPath:] 2909 
tableView:cellForRowAtIndexPath:] 2909 
tableView:cellForRowAtIndexPath:] 2909 
tableView:cellForRowAtIndexPath:] 2909 
tableView:cellForRowAtIndexPath:] 2909 
resultsList: 1370 (this is the last thing that gets logged when my 2nd key is pressed) 
tableView:cellForRowAtIndexPath:] 1370 (this is the first thing that gets logged when my 3rd key is pressed) 
tableView:cellForRowAtIndexPath:] 1370 
tableView:cellForRowAtIndexPath:] 1370 
tableView:cellForRowAtIndexPath:] 1370 
tableView:cellForRowAtIndexPath:] 1370 
tableView:cellForRowAtIndexPath:] 1370 
tableView:cellForRowAtIndexPath:] 1370 
resultsList: 1 (last thing that gets logged when my 3rd key is pressed) 

어떤 생각 :

그래서 기록이야 얻을 것을 좀 더 구체적인 예는 이것이다? 미리 감사드립니다!

답변

0

좋습니다. 알아 냈습니다. reloadData가 작동합니다. 문제는 내가 전화하려고 하였다

[self.searchDisplayController.searchResultsTableView reloadData]; 

대신

[self.SearchController.searchResultsTableView reloadData]; 
관련 문제