简体   繁体   中英

Unable to push view controller when I use UISearchController

I have UISearchcontroller . When I select a searched item and try to push a viewcontroller , the viewcontroller is not being pushed. The reason for this issue is when I set self.definespresentationcontext to NO . Its working if I set the self.definespresentationcontext to YES , but the searchbar beomes hidden.

Example :

    self.searchResultController = [[MyResultsController alloc]init];
    self.searchResultController.delegate = self;
    self.searchController = [[UISearchController alloc] initWithSearchResultsController:self.searchResultController];
    self.searchController.delegate = self;
    self.searchController.hidesNavigationBarDuringPresentation = NO;
    self.searchController.searchBar.delegate = self;
    self.searchController.searchBar.showsCancelButton = YES;
    self.searchController.searchBar.translucent = YES;
    [self.searchController.searchBar sizeToFit];
    self.definesPresentationContext = NO;

Can somebody help me out to solve this issue? Thanks in advance.

Make sure your UIViewController is set to render under Top Bars and then everything should work as expected.

self.definesPresentationContext = YES

Interface Builder

也许

presentingViewController?.navigationController?.pushViewController(eventDetailsViewController, animated: true)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM