How to redirect to a Viewcontroller

Asked

Viewed 162 times

1

for conflict issues between two frameworks, I had to pass the login code from facebook to a helper class, however I’m not sure how to redirect the user to the main screen of the app after the login is done, Someone there can give me a solution for that?

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



    }
  • simply Voce use the method self.performSegue(withIdentifier: "coloca_aqui_o_ID_da_segue", sender: nil) that it goes to Viewcontroller determined by the following ID

1 answer

2


When you remove the Viewcontroller method and put it into a separate class you lose the "self", so you can’t just call self.performSegueWithIdentifier().

What you can do is change the signature of the method 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 loginFacebook implementation 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)
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.