UISearchController Push Segue没有找到SourceController

时间:2017-03-30 02:59:24

标签: ios objective-c iphone segue uisearchcontroller

拜托,我已经尝试过所有可以google了!下面提供的图片!

我有一个主'ProgramTableViewController',它是一个填充了数据数组的TableView。我创建了一个UISearchController(SearchResultsTableViewController),它在ProgramTableViewController顶部的代码中显示,以搜索数组。一旦我点击SearchResultsTableView中的tableview选定行,就可以将Segue推送到第三个“AboutViewController”,该第三个“AboutViewController”设置为填充数组中的所有数据以显示所述数据的所有详细信息。当你从ProgramTableViewController转向AboutViewController时,它工作正常。当您从SearchResultsTableViewController尝试它时,会使用以下错误代码崩溃应用程序:“因未捕获的异常而终止应用程序'NSGenericException',原因:'无法找到segue的导航控制器'aboutViewTwo'。推送segues只能是当源控制器由UINavigationController实例管理时使用。“

我在导航控制器中嵌入了SearchResultsTableViewController,没有修复任何东西。如果我模态地执行segue,那么它的一半是有效的。当您单击该AboutViewController中的某些按钮时,不显示导航栏或标签栏并失败。

(在ProgramViewController中)

pragma mark - 导航

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
    if ([segue.identifier isEqualToString:@"AboutView"] || [segue.identifier isEqualToString:@"AboutView2"]) {

        NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
        AboutViewController *aboutVwController = [segue destinationViewController];
        EventList *obj  =   [arrayEventList objectAtIndex:selectedRowIndex.row];
        aboutVwController.eventObj  =   obj;
}
}

pragma mark - 搜索事件

- (UISearchController *)controller {

    if (!_controller) {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
        SearchResultsTableViewController *resultsController = [storyboard instantiateViewControllerWithIdentifier:@"SearchResults"];
        _controller = [[UISearchController alloc] initWithSearchResultsController:resultsController];
        _controller.searchResultsUpdater = self;
}
    return _controller;
}

pragma mark - 搜索结果更新程序

-(void)updateSearchResultsForSearchController:(UISearchController *)searchController {

    self.results = nil;
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"eventName contains [cd] %@", self.controller.searchBar.text];
    //NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF contains [cd] %@", self.controller.searchBar.text];
    self.results = [self->arrayEventList filteredArrayUsingPredicate:predicate];
}
- (IBAction)searchButtonPressed:(id)sender {
    [self.navigationController presentViewController:self.controller animated:YES completion:nil];
}

(在SearchResultsTableViewController中)

pragma mark - 导航

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"aboutViewTwo"]) {
        NSIndexPath *selectedRowIndex = [self.tableView indexPathForSelectedRow];
        AboutViewController *aboutVwController = [segue destinationViewController];
        EventList *obj  =   [_searchResults objectAtIndex:selectedRowIndex.row];
        aboutVwController.eventObj  =   obj;
}
}

StoryBoard Layout

感谢!!!

1 个答案:

答案 0 :(得分:0)

将segue从Push更改为Modal

(或者,将segue的源控制器嵌入到UINavigationController中。)

您只能在由UINavigationController管理的导航堆栈中使用Push segue。