ios


Using dismissViewController on queue of multiple UIViewControllers with delegate


I'm presenting a tutorial of 4 UIViewController when my app starts the first time.
Every UIViewController has a Button with a segue presenting the next ViewController.
The last ViewController has a button "Let's start" which should dismiss the tutorial completely.
Problem:
It this dismiss all ViewControllers except the first. I don't understand why?!
What I expect:
On the last ViewController4 I'm calling the dismissIntroduction() function of the first ViewController, so I except ALL ViewControllers (ViewController1 included) should disappear.
When I put a button on the first ViewController and call the function "dismissIntroduction()" it disappears.
ViewController 1 (WelcomeViewController):
protocol WelcomeViewDelegate {
func dismissIntroduction()
}
class WelcomeViewController: UIViewController, WelcomeViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
func dismissIntroduction() {
self.dismissViewControllerAnimated(true, completion: nil)
}
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let destination = segue.destinationViewController as! ViewController2
destination.delegate = self
}
}
ViewController 2:
class ViewController2: UIViewController {
var delegate:WelcomeViewDelegate?
override func viewDidLoad() {
super.viewDidLoad()
}
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let destination = segue.destinationViewController as! ViewController3
destination.delegate = self.delegate
}
}
ViewController 3:
class ViewController3: UIViewController {
var delegate:WelcomeViewDelegate?
override func viewDidLoad() {
super.viewDidLoad()
}
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
let destination = segue.destinationViewController as! ViewController4
destination.delegate = self.delegate
}
}
ViewController4 (the last one):
class ViewController4: UIViewController {
var delegate:WelcomeViewDelegate?
override func viewDidLoad() {
super.viewDidLoad()
}
#IBAction func pressLetsStart(sender: AnyObject) {
self.delegate!.dismissIntroduction()
}
}
EDIT:
I got it working, when I put the dismissViewControllerAnimated function TWO times!?
func dismissIntroduction() {
self.dismissViewControllerAnimated(true, completion: nil)
self.dismissViewControllerAnimated(true, completion: nil)
}
But why? I don't understand the logic behind...
You are looking at the wrong solution to your problem, what you need to do is look for Unwind Segues. Go through this tutorial: https://spin.atomicobject.com/2014/10/25/ios-unwind-segues/
I solved the problem now with following function in last ViewController:
#IBAction func pressLetsStart(sender: AnyObject) {
self.dismissModalStack()
}
private func dismissModalStack() {
var vc = self.presentingViewController! as UIViewController
while (vc.presentingViewController != nil) {
vc = vc.presentingViewController!;
}
vc.dismissViewControllerAnimated(true, completion: nil)
}

Related Links

iOS when one views height increase with code , alignment is deteriorating
iCloud KVStore - Code Signing Entitlements Error
Swift UITableView not showing all result
Remove All Cell Accessories in UITableView in Swift 2
iOS9 Developer Trust App No Internet Connection Error
appMessagesGetIsSupported is false for appMessagesGetIsSupported
Making a mixed Objective-C & Swift Framework
How do i access the textField in my alertView? Trying to see if password matches current user. parse/swift
How to play MP3 From URL in iOS
Restkit 0.24.1 POST to Server and get response synchronously
UITableView has extra space on top during “pull down to refresh”
KeychainItemWrapper class getting error in ios 9
library not found for -lCloudinary
Can't create ipa from Xcode 7
How to use normal button instead of bar button item
How to get screenshot image

Categories

HOME
sbt
math
web-applications
copy
compiler-errors
parse.com
bootstrap-selectpicker
svg.js
oracle-adf
wget
overloading
wavelet
silk-performer
lexikjwtauthbundle
ghost-blog
similarity
rgdal
montecarlo
hawq
stylesheet
simple-html-dom
azure-api-apps
dokuwiki
pvlib
chamilo-lms
mask
bits
joe-editor
bem
eve
firedac
website-hosting
html-lists
unityscript
biological-neural-network
jawr
hipi
jce
haste
lcov
facebook-canvas
omniauth
ipopt
directsound
winobjc
gcloud-java
mysqladmin
xirr
symbian
push-api
julian
spinach
google-swiffy
fortrabbit
boxapiv2
epoll
master-theorem
keyboard-navigation
jxta
mod-python
apache-commons-dbcp
polarssl
jflow
hogan.js
clean-urls
google-profiles-api
expressionvisitor
ember-router
mdi
gemstone
directoryentry
hunchentoot
mkmapviewdelegate
high-traffic
remote-control
n900
dynamic-websites
iphone-sdk-3.1
sqlprofileprovider

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App