微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ios – 在呈现UINavigationController模式时,segue.destinationViewController为nil

我有一个UICollectionView,当用户按下一个单元格时,我使用一个故事板以模态方式呈现UINavigationController中的另一个视图控制器.
- (void)collectionView:(UICollectionView *)collectionView
didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    [self performSegueWithIdentifier:@"editBookIPad"
                                      sender:indexPath];
}


- (void)prepareForSegue:(UIStoryboardSegue *)segue
                 sender:(id)sender
{
    // Did not include code for other segues,but I check which is the current one properly
    UINavigationController *dest = segue.destinationViewController; // This is nil!
    dest.modalPresentationStyle = UIModalPresentationFormSheet;
    DetailsViewController *detailsVC = (id)[dest topViewController];
    detailsVC.stack = self.stack;
    detailsVC.editingMode = 1;
    detailsVC.bookToEdit = [self.fetchedResultsController objectAtIndexPath:sender];
    [self.collectionView deselectItemAtIndexPath:sender
                                        animated:YES];
}

现在,我的问题是segue.desinationViewController返回nil(如代码片段中的注释所示).

只是为了调试,我将UINavigationController更改为另一个视图控制器,我没有问题.我不知道是否从modal更改为push作为转换样式会有所帮助,因为它不可能推送UINavigationController(发生崩溃的情况就是这样).

我清理了项目和构建文件夹,然后重新启动了我的计算机(以及Xcode).

这是运行应用程序时的样子:

在寻找类似的问题时,我发现了这一点.大多数其他问题是关于在目标视图控制器上设置的属性为nil(例如this).

我使用Xcode 5.1.1并将iOS 7.0作为开发目标.

EDIT1

现在我的应用程序的所有部分都出现了同样的问题(UINavigationController以模态方式呈现).但是,它只在某些情况下发生,但每次segue.destinationViewController仍为零.

EDIT2

我用这个替换了prepareForSegue代码(手动完成):

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Storyboard"
                                                     bundle:nil];
UINavigationController *navCon = [storyboard instantiateViewControllerWithIdentifier:@"AllBooksVCDetails"]; // The problematic navigation controller
navCon.modalPresentationStyle = UIModalPresentationFormSheet;
BKSBookDetailsViewController *detailsVC = (id)[navCon topViewController];
detailsVC.stack = self.stack;
detailsVC.editingMode = 1;
detailsVC.bookToEdit = [self.fetchedResultsController objectAtIndexPath:indexPath];
[self presentViewController:navCon
                   animated:YES
                 completion:nil];
[self.collectionView deselectItemAtIndexPath:indexPath
                                    animated:YES];

这很有效.所以我认为问题出在故事板上.

解决方法

将tracecontroller嵌入到NavigationController中时遇到了同样的问题.
override public func prepareForSegue(segue: UIStoryboardSegue,sender: AnyObject?) {

        let destinationVC = segue.destinationViewController as! UINavigationController
        let nextViewController = destinationVC.viewControllers[0] as! SecondViewController

        nextViewController.someProperty = someValue
    }

这个链接帮助我:

https://www.andrewcbancroft.com/2015/06/02/access-sub-controllers-from-a-uinavigationcontroller-in-swift/

原文地址:https://www.jb51.cc/iOS/330983.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐