[英]Changing View Controllers Behind a Modal View Controller
我想為聯系人應用程序創建類似於完成/編輯頁面的內容。 模態視圖后面的視圖似乎發生了變化,但是我不確定這是如何產生這種行為的。
這是我到目前為止所看到的:
iOS:在當前模式視圖控制器后面切換視圖控制器? 看來這篇文章有一個正確的答案。 但是,我不確定他making the root view controller a delegate of the modal view
設為making the root view controller a delegate of the modal view
什么意思,以及call a delegate method
是什么意思。
這是我想要完成的:
想象一個嵌入在導航控制器中的 vc1。 我點擊 vc1 上的一個按鈕,這會導致 vc2 以模態呈現。 當您在 vc2 上按“完成”時,它會關閉模式視圖 vc2,並顯示 vc3。 當您點擊 vc3 上的后退按鈕時,它會返回到 vc1。
這是當前的行為:
我可以模態地讓 vc2 顯示在 vc1 之上。 但是當在 vc2 上按下“完成”按鈕時,它只是返回到 vc1 而不是去 vc3 然后,當點擊“返回”時,去到 vc1。
這是我已經嘗試過的:
我嘗試在沒有動畫的情況下從 vc1 轉為 vc3,然后模態轉為 v2。 這種工作非常難看的過渡,它會導致Presenting view controllers on detached view controllers is discouraged
上顯示Presenting view controllers on detached view controllers is discouraged
錯誤顯示。 此外,我嘗試了unwindToSegue
方法的不同組合,但我也無法弄清楚。
任何幫助將非常感激! 非常感謝您的參與 :)
您可以通過在 vc1 中創建協議並將其作為模態視圖控制器的屬性來使根視圖控制器 (vc1) 成為模態視圖控制器的委托。 當您關閉模態視圖控制器時,調用其中一種委托方法。 像這樣的事情可能對你有用:
vc1:
protocol Vc1Delegate: class {
func pushToVc3()
}
class Vc1: UIViewController, Vc1Delegate
{
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "Vc2Modal" {
if let _vc2 = segue.destinationViewController as? Vc2 {
_vc2.delegate = self
}
}
}
@IBAction func showVc2Modal() {
performSegueWithIdentifier("Vc2Modal", sender: nil)
}
// MARK: Vc1Delegate
func pushToVc3() {
performSegueWithIdentifier("Vc3PushWithoutAnimation", sender: nil)
}
}
VC2:
class Vc2: UIViewController
{
weak var delegate: Vc1Delegate?
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func dismiss() {
delegate?.pushToVc3()
dismissViewControllerAnimated(true, completion: nil)
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.