尝试呈现视图控制器时崩溃

时间:2016-10-25 18:41:15

标签: ios objective-c

执行以下代码时,我的应用程序出现崩溃:

- (void)presentSearchViewController
{
    if(!_searchController)
    {
        SearchStickerViewController *searchController = [[SearchStickerViewController alloc] initWithNibName:@"SearchStickerViewController" bundle:nil];
        searchController.delegate = self;
        [searchController.view setFrame:CGRectMake(0,0,self.view.frame.size.width, self.view.frame.size.height)];
        _searchController = searchController;
    }

    [self addChildViewController:_searchController];        
    [self.view addSubview:_searchController.view];
    [_searchController didMoveToParentViewController:self];
}

奇怪的是,我使用相同的代码来推送其他的ViewControllers,它运行得很好。它并不总是崩溃,它在我第五次来回转动后开始崩溃(也许它在6日或7日崩溃)。

我得到的错误是:

  

由于未捕获的异常而终止应用   UIViewControllerHierarchyInconsistency',原因:'子视图   控制器:其中UICompatibilityInputViewController:0x1004e6af0>应该   有父视图控制器:< CKFullScreenAppViewController:   0x104e458f0>但实际的父母是< UIInputWindowController:   0x100830200>

我用来解散ViewController的代码是:

- (void)dismissSearchResultsViewController
{
    [_searchController willMoveToParentViewController:nil];
    [_searchController.view removeFromSuperview];
    [_searchController removeFromParentViewController];
}

有关如何解决/解决此问题的任何想法?

0 个答案:

没有答案