如何在swift中重新显示从子视图控制器解析登录

时间:2015-05-25 17:59:55

标签: ios swift uiviewcontroller parse-platform uitabbarcontroller

如果解析会话不存在,我有一个从UITabBarController(我的应用程序的根目录)触发的视图控制器。

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)
    }
}

哪个效果很好。但是我遇到的问题是当从标签栏控制器中的子视图控制器调用注销时如何触发此代码

@IBAction func logoutAction(sender: AnyObject)
{
    PFUser.logOut()
    // ... what should i call here...
}

1 个答案:

答案 0 :(得分:1)

协议和代表可能是您正在寻找的内容: The Swift Programming Language - Protocols

基本上,您可以声明您的UIViewController符合协议。然后在根视图控制器中(或在初始化的任何位置)设置代理

然后,你可以这样做:

@IBAction func logoutAction(sender: AnyObject)
{
    PFUser.logOut()
    delegate?.loggedOut()
}