2010-08-23 9 views
30

웹에서 새 데이터를로드하기 때문에 사용자가 "검색"버튼을 클릭하면 UISearchDisplayController를 닫고 싶습니다. 프로그래밍 방식으로 컨트롤러를 닫으려면 어떻게합니까? 이미 적절한 메소드가 호출되었지만이를 수행하는 방법을 모릅니다.UISearchDisplayController를 프로그래밍 방식으로 닫으려면 어떻게해야합니까?

나는 아래가 작동 할 것이라고 생각했지만 틀렸어.

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar { 
    [self.searchDisplayController finalize]; 
} 

답변

68
[self.searchDisplayController setActive:NO animated:YES]; 

즐길 수 있습니다.

+1

대단히 감사합니다. 2012 년에도 큰 성과를 거두었습니다. :) – Xtrician

+0

이것은 나에게 효과가 없었습니다. 나는 사용자가 어딘가에 탭을 한 번 말했다 - (void) tableView : (UITableView *) tableView didSelectRowAtIndexPath : (NSIndexPath *) indexPath {[self.searchDisplayController setActive : NO animated : YES];} 그러나 이렇게하면 사라지지 않았다. 이 메소드는 호출되었지만 결과는 없습니다. – coolcool1994

+0

완벽. viewWillDisappear에서 이것을 사용하고 있습니다. 내가 필요한 것. –

3

귀하는 주 스레드에서 false로 활성으로 설정되었는지 확인해야합니다

dispatch_async(dispatch_get_main_queue(), ^{ 
    [self.searchDisplayController setActive:NO animated:YES]; 
}); 
2
func setActive(_ visible: Bool, 
    animated animated;: Bool) 

것은 당신이 빠른 사용하는 경우.

+0

사실 Swift의 경우 속성이 '활성'입니다. – gigo

관련 문제