我使用UISearchController时无法推送视图控制器

时间:2015-07-10 08:46:11

标签: ios objective-c uisearchbar uisearchcontroller

我有UISearchcontroller。当我选择搜索到的项目并尝试推送viewcontroller时,viewcontroller未被推送。这个问题的原因是我将self.definespresentationcontext设置为NO。如果我将self.definespresentationcontext设置为YES,但搜索栏可以隐藏,则可以正常工作。

示例:

    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;

有人可以帮助我解决这个问题吗? 提前谢谢。

2 个答案:

答案 0 :(得分:0)

确保您的UIViewController设置为在Top Bars下呈现,然后一切都应该按预期工作。

  

self.definesPresentationContext = YES

Interface Builder

答案 1 :(得分:0)

也许

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