I have a button that goes to another view. I want to perform some code before the segue moves. The problem I am facing is the segue goes to the other page before the code has a chance to finish. So the values that are in the User default don't get changed before the view gets changed. My question is how can I get the code to run and after its done get the segue to fire? Here is what I have so far:
@IBAction func onLogoutClick(sender: AnyObject) {
//clear all url chache
NSURLCache.sharedURLCache().removeAllCachedResponses()
//null out everything for logout
email = ""
password = ""
self.loginInformation.setObject(self.email, forKey: "email")
self.loginInformation.setObject(self.password, forKey: "password")
self.loginInformation.synchronize()
//self.view = LoginView
}
performSegueWithIdentifier
in your@IBAction
function. The other approach is to get rid of the@IBAction
method and implementprepareForSegueWithIdentifier
– Paulw11 May 27 '16 at 1:41