I have a view controller which is triggered from a UITabBarController (which is the root of my app) if a parse session doesn't exist.
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.initialiseLogin()
}
func initialiseLogin()
{
if (PFUser.currentUser() == nil) {
let storyboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc: UIViewController = storyboard.instantiateViewControllerWithIdentifier("LoginView") as! UIViewController
self.presentViewController(vc, animated: false, completion: nil)
}
}
Which works great. However the problem i'm having is how do i trigger this code when a logout is called from a child view controller in the tab bar controller
@IBAction func logoutAction(sender: AnyObject)
{
PFUser.logOut()
// ... what should i call here...
}
Protocols and delegates might be what you're looking for: The Swift Programming Language - Protocols
Essentially, you can declare your UIViewController
s to conform to a protocol. Then set the delegates in your root view controller (or wherever you do your initialisation)
Then, you can do something like this:
@IBAction func logoutAction(sender: AnyObject)
{
PFUser.logOut()
delegate?.loggedOut()
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.