나는 그렇게처럼 내 searchDisplayController과 검색 창을 설정 :searchDisplayController 대리자 메서드는 언제 호출됩니까?
if ([self conformsToProtocol:@protocol(UISearchDisplayDelegate)]) {
NSLog(@"conform to search display");
}
내의 ViewController .H 파일이 있습니다 :
<UITableViewDelegate, UITableViewDataSource, UISearchBarDelegate, UISearchDisplayDelegate>
를 내의 ViewController이 단지의 경우 클래스에 부합하는 경우
UISearchBar *aSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 150, 44)];
self.reportSearchBar = aSearchBar;
_reportSearchBar.tintColor = DARKGRAY_COLOR;
_reportSearchBar.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
_reportSearchBar.delegate = self;
[aSearchBar release];
UISearchDisplayController *searchDisplayCtlr = [[UISearchDisplayController alloc] initWithSearchBar:self.reportSearchBar contentsController:self];
self.reportSearchDisplayController = searchDisplayCtlr;
self.reportSearchDisplayController.searchResultsDataSource = self;
self.reportSearchDisplayController.searchResultsDelegate = self;
[searchDisplayCtlr release];
UIBarButtonItem *searchBBI = [[UIBarButtonItem alloc] initWithCustomView:_reportSearchBar];
self.reportSearchBBI = searchBBI;
[searchBBI release];
[self.navigationItem setRightBarButtonItem:_reportSearchBBI animated:NO];
내가 확인
그러나 중단 점은 다음과 같습니다.
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
[self filterContentForSearchText:searchString];
return YES;
}
그리고 결코 거기에 도달하지 않습니다. UISearBarDelegate 메서드 중 하나를 구현하고 해당 메서드를 가져옵니다. Apple의 예제 코드 TableSearch를 실행하면 위에서 복사 한 searchDisplayController 대리자 메서드가 실행됩니다. 그래서 나를 위해 검색 표시 줄에 텍스트를 넣으려고하면 필터링 된 목록에는 searchDisplayController 대리자가 호출되지 않으므로 아무 객체도 없으므로 내 응용 프로그램이 충돌합니다.
생각하십니까? 감사!
죄송합니다, 버그를 발견했습니다. 나는해야한다는 것을 몰랐다 :'self.reportSearchDisplayController.delegate = self'도 : - \. – Crystal
당신이 당신의 자신의 오류를 발견했다는 멋진 :) 나는 같은 순간에 나의 대답을 쓰고 있었다 : – NDY