ios


prepareForSegue not opening new view


I have a view controller that is called. It has some checks in it that if they are not met, it doesn't need to be show this view controller, and the next view controller in my application will be called. This is partially not working.
I have the following IBAction:
#IBAction func nextBtnPressed(sender: UIButton!) {
if GlobalVars.diceRollFirst == true {
performSegueWithIdentifier("showCombatOutcomeFromRearSupport", sender: self)
}
if GlobalVars.diceRollFirst == false {
performSegueWithIdentifier("showDiceRollFromRearSupport", sender: self)
}
}
Which works correctly.
However in my viewDidLoad() I have the following code:
rearsupportfound is set earlier in the viewDidLoad after many checks. It's initially false and is set true if any of the checks are met.
if !rearsupportfound {
println("rearsupportfound is: \(rearsupportfound)")
if GlobalVars.diceRollFirst == true {
performSegueWithIdentifier("showCombatOutcomeFromRearSupport", sender: self)
}
if GlobalVars.diceRollFirst == false {
performSegueWithIdentifier("showDiceRollFromRearSupport", sender: self)
}
}
This code does nothing. By that I mean it does get to this code:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
if segue.identifier == "showCombatOutcomeFromRearSupport" {
println("segue: showCombatOutcomeFromRearSupport sender: \(sender)")
let vc = segue.destinationViewController as CombatOutcomeViewController
vc.army1 = army1
vc.army2 = army2
}
if segue.identifier == "showDiceRollFromRearSupport" {
println("segue: showDiceRollFromRearSupport")
let vc = segue.destinationViewController as DiceRollViewController
vc.army1 = army1
vc.army2 = army2
}
}
And I get the println entries, but the requested view controller is never presented and the current view controller is. The same perpareForSegue works perfectly when the button is pressed.
Any idea's why??
I realize that I should probably do the check for presenting this view controller before I even get here. I was trying to avoid writing the code twice, since the data displayed in the view hide's or display's certain labels and buttons. I haven't seen a good way for me to get around this, so since I had already written these checks, was trying to bypass the view controller within itself, depending on the values. Thoughts anyone? Thanks.
Your code isn't working because you're calling it from within viewDidLoad(). You need to call it from viewDidAppear() instead - see this question for more details.
As far as your code duplication issues, I would try to remove all game logic from your view controllers. Have a larger, higher level object that maintains the state of the game, and decides which view controllers are applicable at any given moment / scenario. Then this object can hand the appropriate segue identifier to the view controller. This way the view controller doesn't need to know about dice or combat or rear support.

Related Links

System.ArgumentException: Keyword not supported “pwd”
autolayout error when landscape my screen
Read values from localized file iOS
How to move code execution to the main qeue
How to make a custom relational operator in Swift
Xcode 8 APS Environment Entitlement won't set to production
How to play a sound from an array when tap a button in a collection view cell in Swift 3?
Observable for selector - RxSwift
URLCache.shared behavior on iOS 9 and Above
Get user position (background app) each 5 minutes in iOS
How to create an image pixel by pixel
Can't seem to get Parse includeKey working
Update device data on IoT for Automotive Starter Application using Bluemix iOS Client api
didSelectRowAt called only on multitouch
Searching for a substring in string in Swift not working
Track location of iphone and notify if crosses certain kilometeres in ios Objective C

Categories

HOME
opencl
office-js
dicom
spring-roo
bootstrap-selectpicker
weight
chronicle
redhat
android-sms
go-gorm
autofac
asciidoc
hyperion
boxfuse
jsqmessagesviewcontroller
factory-girl
phpbb3
web-audio
data-annotations
countdown
slowcheetah
google-finance
beanstalkd
multiprocessing
netcdf
montecarlo
precision
smallbasic
physics
scalability
regex-group
point-cloud-library
angular2-databinding
localdb
detach
folly
transpose
partition
linechart
gradle-tooling-api
tern
slt
kendo-chart
simplesamlphp
easyhook
breach-attack
replicate
zenity
vs-2015-preview
sizing
android-sdk-tools
mailcore2
measurement-protocol
telecommunication
menustrip
vsvim
accounts
viewengine
metalkit
relaxng
asp.net-authorization
post-processor
appv
keypad
gem
alienvault
fastparse
fortrabbit
javaw
puppet-enterprise
simpleadapter
excel-charts
gnat
lwuit-list
b2b
requiredfieldvalidator
windows-phone-7.1
django-endless-pagination
emacs-jedi
nsimageview
jflow
northwind
wescheme
browserid
vote
mixing
hiphop
xml-dtd
vim-fugitive
time-limiting
intel-8080
ssao
jdic
nstreecontroller
jquery-1.3.2
pastebin
myisam
68hc11
nhaml
web-based
usenet

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