Reputation: 427
I am having a brain block. After combing the SO database I am at a loss as to why this segue is not executing. It took me long enough to figure out how to reset my NSUserDefaults. When I finally did, I figured this would work fine. After all, I have set up many segues in my app. Now, this one does nothing.
func isAppAlreadyLaunchedOnce()->Bool{
let defaults = NSUserDefaults.standardUserDefaults()
if let isAppAlreadyLaunchedOnce = defaults.stringForKey("isAppAlreadyLaunchedOnce"){
println("App already launched")
return true
}else{
defaults.setBool(true, forKey: "isAppAlreadyLaunchedOnce")
println("App launched first time")
performSegueWithIdentifier("showEULA", sender: self)
return false
}
}
The log shows the "App launched first time" text so I would expect the segue to execute. However, noting happens. Please help. Thank you.
Upvotes: 1
Views: 81
Reputation: 491
try dispatch_async on the main_queue. call the function in viewWillAppear.
func segue() {
dispatch_async(dispatch_get_main_queue(),{
self.performSegueWithIdentifier("showEULA", sender: nil)
})
}
Upvotes: 1
Reputation: 6662
Something needs to own the performSegueWithIdentifier().
Call it from your your initial UIViewController, like
self.performSegueWithIdentifier("showEULA", sender: self)
//OR FROM ANOTHER CLASS
refToMainVC.performSegueWithIdentifier(...)
Also your user default checking is wrong I think, you are setting a bool but reading a string. You can use boolForKey() instead.
Upvotes: 0
Reputation: 386
Where are you creating the segue? If you put up the code where you're creating the segue or explain how you're creating it in Interface Builder that would help explain why it's not working. It's possible you haven't associated the "showEULA" identifier with the segue.
Upvotes: 0