IOS: the visibility bar is hidden when the search bar is displayed in the navigation bar

I am trying to get the search bar and its scope in the navigation bar, just as the view first opens. If you simply drag and drop the UISearchBar onto the table view controller in the interface builder, it will be placed in your table as a header cell. Then, when you click on it, it comes to life in education, which I will be lower. The problem is that I want this to start without any click, with the right button on the left and without the cancel button on the right:

enter image description here

So, in order to immediately adjust the search focus without clicking, I tried adding [_searchBar becomeFirstResponder];to viewDidLoad, which does not work. Then I tried:

self.searchDisplayController.displaysSearchBarInNavigationBar = YES;

, ( ), .

enter image description here

UINavigationBar . , , .

, - . , UITableViewController ( UIRefreshConrol), . .

+4
1

tl; dr: .

, UISearchBar headerView UITableView - UIKit, . iOS 6 , iOS 7 .

becomeFirstResponder viewDidLoad , , (, NIB). , . viewDidAppear: , , becomeFirstResponder UISearchBar .

( ) UISearchBar. subviews :

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self recurseSubviewsForView:self.searchDisplayController.searchBar];
}

- (void)recurseSubviewsForView:(UIView *)view
{
    for (UIView *subview in view.subviews) {
        if ((CGRectGetMinY(subview.frame) == CGRectGetMaxY(self.searchDisplayController.searchBar.frame)) && subview.hidden) {
            subview.hidden = NO;
            self.searchDisplayController.searchBar.showsScopeBar = YES;
            [self.searchDisplayController.searchBar sizeToFit];
        }
        [self recurseSubviewsForView:subview];
    }
}

, , . , , , , , , , ..

, , - , ? , , , , . "" , , . , ? , Apple. , , . Apple . . -. , UISearchBar headerView UITableView... , , .

, , iOS 8, , UISearchDisplayController. UISearchController. , .

+4

Source: https://habr.com/ru/post/1569353/


All Articles