我想解雇一个ViewController并提出另一个ViewController。这里是我的代码:关闭一个ViewController,并提出另一个ViewController - IOS - Swift 3
MainVC:
@IBAction func loadFirstVCClicked(_ sender: UIButton)
{
self.present(FirstViewController.loadVC()
}
FirstViewController:
static func load() -> FirstViewController
{
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "FirstViewController") as! FirstViewController
return vc
}
@IBAction func exitClicked(_ sender: UIButton)
{
self.dismiss(animated: true, completion: {
self.present(SecondViewController.loadVC()
})
}
SecondViewController:
static func loadVC() -> SecondViewController
{
let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "SecondViewController") as! SecondViewController
return vc
}
@IBAction func exitClicked(_ sender: UIButton)
{
self.dismiss(animated: true, completion: {
//present MainVC - second VC should work as an interstitial ad
})
}
而且我得到这个错误:“SecondViewController上FirstViewController,其观点是不在窗口层次!“
而且它不显示。所以基本上我想要的SecondViewController是SecondViewController的dissmisal和MainVC didLoad
基本方案之间的一种插页式广告:从
FirstViewController-> SecondViewController-> MainVC
任何建议,你会真的很感激。谢谢!
您正在尝试从已经被解雇的FirstViewController呈现。你应该从MainVC出席。 – orxelm
我会去使用一个由MainVC实现的代理,当你想关闭它时由SecondVC调用它。然后MainVC驳回SecondVC并呈现FirstVC –