繁体   English   中英

如何覆盖代码中的segue类型?

[英]How to override kind of segue in code?

简而言之,我有一个从FirstViewControllerSecondViewController Show SecondViewController
我从FirstViewController两个地方在iPad和iPhone上调用它。 可以,但是在一种情况下,我需要将SecondViewController.Popover

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {

    if let secondViewController = segue.destinationViewController as? SecondViewController {

        if let cell = sender as? UITableViewCell, indexPath = tableView.indexPathForCell(cell) {

            let student = fetchedResultsController.objectAtIndexPath(indexPath) as! Student
            secondViewController.schoolClass = schoolClass
            secondViewController.student = student

        } else {

            secondViewController.modalPresentationStyle = .Popover
            secondViewController.schoolClass = schoolClass

            let popoverPresentationController = studentFormViewController.popoverPresentationController
            popoverPresentationController!.delegate = self
            popoverPresentationController?.permittedArrowDirections = .Up
            popoverPresentationController?.barButtonItem = addStudentBarButtonItem
        }
    }
}

它不起作用。

有什么想法如何在代码中从情节提要中替换类型的segue?

您应该使用自定义序列:

  1. 通过子类化UIStoryboardSegue类并重写prepare()方法来实现自定义segue。 (在prepare()方法中,实现所有必需的行为(控制器动画,演示等等,具体取决于您的情况);
  2. 在界面构建器中将您的segue类型从push更改为custom,然后在class属性中选择您的实现(如下图所示)

使用自定义segue

最好的祝福!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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