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

UIWebview remove padding / margin
How do I not get optional in the output?
Material Select blinking on iOS
How to get the Core data Primary key value in ios Swift? [duplicate]
How to remove only minutes from UIDatePickerMode.DateAndTime
UIButton click causing app freeze/Rapid increase in memory
libobjc.A.dylib objc_msgSend crash occurring with core data usage in background thread
Disabling Dynamic Type in Swift
how to make overlay with activity indicator programatically
performseguewithidentifier works with a delay
Type [TeamModel] has no subscript members
Pdf file in webview not scrolling
Ternary Conditional Operator for nil/not nil
Xamarin / IOS / Azure - No 'id' member found on type
iOS 9 core location crash
Better accessibility label for a clickable table view cell

Categories

HOME
wpf
performance
mongodb
asp.net-identity
f#
compliance
orbeon
android-sqlite
linear-programming
quickblox
windows-runtime
stack
visual-studio-2012
delphi-xe7
activerecord
proftpd
executable
reload
garmin
aerospike
collision
windows-applications
man
core-location
precision
slf4j
grouping
webfocus
opensuse
kubernetes-go-client
skyscanner
lync
seh
pymssql
aem-6
azure-app-service-envrmnt
bits
disqus
ecdsa
cookiestore
amazon-elasticsearch
dxgi
php-5.5
spark-submit
codeigniter-hmvc
free-diameter
msysgit
invalidate
gulp-babel
hostapd
jquery-masonry
xssf
laravel-routing
libev
jce
jvm-arguments
assembly-references
mysql-error-1050
geneticsharp
vs-2015-preview
kombu
blocking
perspective
jasny-bootstrap
facebook-audience-network
mongolab
facebook-comments
jca
android-popupwindow
uac
materialdrawer
delphi-10-seattle
emberfire
fortrabbit
computer-science-theory
sendto
asf
before-save
pkcs#10
twill
keyboard-navigation
youtrack-api
css3pie
acts-as-taggable-on
mongo-shell
sysadmin
floating-point-conversion
repeating
geometry-surface
google-chrome-frame
progressdialog
guice-servlet
wpf-4.0
jcycle
working-directory
ruby-1.9.2
duplicate-data
sdl.net
treetop
etrade-api
nsindexset
ryz
drupal-gmap
sharepoint-feature
fogbugz-on-demand
mud

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