如何在 iOS8 中的 viewDidLoad() 中调用此函数

How can I call this function in viewDidLoad() in iOS8

我想在 viewDidLoad 中调用此函数,但我不知道该怎么做。你能帮帮我吗?

  func loginWithFacebook(withcompletionHandler: (success:Bool) ->()){
        var permissions : Array = [ "user_location","public_profile"]
        PFFacebookUtils.logInInBackgroundWithReadPermissions(permissions, {
            (user: PFUser?, error: NSError?) -> Void in
            if let user = user {
                if user.isNew {
                    println("User SIGNED UP and logged in through Facebook!")
                    self.fetchUserInforFromFacebook(withcompletionHandler)

                    println("User logged in through Facebook!")
                    withcompletionHandler(success: true)
                }
            } else {
                println("Uh oh. The user cancelled the FACEBOOK LOGIN.")
                self.showErrorMessage(error!)
                withcompletionHandler(success: false)
            }
        })
    }

因此,为了调用您的方法,请将其添加到您的 viewDidLoad:

override func viewDidLoad() {
    super.viewDidLoad()
    self.loginWithFacebook { (success) -> () in
        // Your code.
    }
}
override func viewDidLoad() {
   super.viewDidLoad()
   self.loginWithFacebook { (success) -> () in
     if success { //succeeded } else { //failed } }
   }
}

如果你在函数中调用函数

override func viewDidLoad() {
    super.viewDidLoad()
    self.loginWithFacebook { (success) -> () in
        // Your code.
    }
}

如果你想在同一个函数中调用它,那么

override func viewDidLoad() {
    super.viewDidLoad()
    loginWithFacebook { (success) -> () in
        // Your code.
    }
}