我想解僱一個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 –