0

I have a parentview which has 2 child views, I am trying to show a uiviewcontroller as "Present modally" I use the following code:

class ParentCtrl: ButtonBarPagerTabStripViewController {
    let obj = ChildCtrl()
override func viewDidLoad() {
        super.viewDidLoad()
        obj.someClassMethod()
    }
}

class ChildCtrl: UIViewController, IndicatorInfoProvider {
   struct Storyboard {
    static let segue_id = "segue_id"
}
   public func someClassMethod(){
        self.performSegue(withIdentifier: Storyboard.segue_id, sender: self)
    }

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        if(segue.identifier == Storyboard.segue_id){
            let destino = segue.destination as! NewViewController
            destino.seleccion = seleccion
        }
    }
}

But I get the following error:

has no segue with identifier 'segue_id'' But Yeah, I have that identifier because if I copy:

self.performSegue(withIdentifier: Storyboard.segue_id, sender: self)

in the viewDidload method the NewViewController is presented

How can I solve that?

4

2 回答 2

0

您只是在创建一个实例,ChildCtrl而不是使用来自情节提要的实例。结果,该实例对任何故事板文件一无所知,因此没有执行转场的上下文。

您需要从屏幕上的实例ChildCtrl执行 segue 。

于 2018-10-29T07:23:26.513 回答
0

指定Storyboard Segue 标识符,即

在此处输入图像描述

并在编写代码时使用这个id来执行segue,即

self.performSegue(withIdentifier: "segue_id", sender: self)

编辑:

创建objstoryboard,即

let obj = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "ChildCtrl") as! ChildCtrl
于 2018-10-29T07:10:34.717 回答