How to redirect to a ViewController

1

For conflicts between two frameworks, I had to pass the facebook login code to an auxiliary class, however I'm not sure how to redirect the user to the main screen of the app once the login is done, Someone there can give me a solution to this?

  @IBAction func loginFacebook(sender: AnyObject) {
    let util = Util()
    util.loginFacebook()
}
 /*Método na classe util*/
func loginFacebook(){
    let permission = ["public_profile"]
    PFFacebookUtils.logInInBackgroundWithReadPermissions(permission)
    let requisicao = FBSDKGraphRequest(graphPath: "me", parameters:["fields":"id, name, gender,age_range, email"])

    requisicao.startWithCompletionHandler { (connection, result, error) in
        if error != nil{
            print(error)


        }else if let resultado = result{
            let dados = resultado as! NSDictionary
            // redirecionar para pagina principal junto com os dados
        }



    }
    
asked by anonymous 06.10.2016 / 06:35

1 answer

2

When you remove the ViewController method and put it in a separate class you lose the "self", so you can not simply call self.performSegueWithIdentifier ().

What you can do is to change the method signature to

func loginFacebook(viewController: UIViewController)

With this, when you call this method from any viewController you pass as self parameter:

Util.loginFacebook(self)

Within the implementation of loginFacebook you need to call performSegue as follows:

func loginFacebook(viewController: UIViewController) {
    ...
    }else if let resultado = result{
        let dados = resultado as! NSDictionary
        // redirecionar para pagina principal junto com os dados
        viewController.performSegueWithIdentifier("Identifier", sender: viewController)
    }
    
17.10.2016 / 03:20