Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
185 views
in Technique[技术] by (71.8m points)

How to dismiss VIewController iOS Swift

I am new to iOS development. I am developing an application using iOS Swift. I have 3 view controllers viewController1, viewController2, viewController3. When I click from viewController1 its move to viewController2. By using the following code

let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let secondViewController = storyboard.instantiateViewControllerWithIdentifier("viewController2")
        presentViewController(secondViewController, animated: false, completion: nil)

Now I am moving from viewController2 to viewController3 by using the following code

performSegueWithIdentifier("viewController3", sender: scoreColorArray);

It's all fine. Now I want to back from viewController3 to viewController1. My problem it is not going to viewController1 it is going to viewController2. I know the reason viewController2 not dismissed.

I want to dismiss the current view controller and start new one. How can I do it? I know there is some ways to do it, please someone help me to finds the issue.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Since your presentation sequence is VC1 -> VC2 -> VC3 you need to call self.presentingViewController?.presentingViewController?.dismissViewControllerA??animated on VC3, traversing this way your sequence in reverse.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...