ios - Swift: How to send data from loginView to other views? -
i have loginview , can switch other views slide-out-menu swrevealcontroller.
the storyboard looks this: http://imgur.com/a/qx3tj
i token alamofire in loginviewcontroller , want send mainpageview prepareforsegue
override func prepare(for segue: uistoryboardsegue, sender: any?) { if (segue.identifier == "loginsegue") { personresource.gettoken(username: usernametf.text!, password: passwordtf.text!){ token in let mainpagevc = segue.destination as! mainpageviewcontroller mainpagevc.token = token } } }
when click on login error:
unrecognized selector sent instance
what proper way this?
can change login code this:
func login(){ personresource.gettoken(username: usernametf.text!, password: passwordtf.text!){ token in if let t = token as? string{ performsegue(with:"loginsegue", sender:token) } } }
and after retrieve token api you'll perform segue "loginsegue"
and need modify prepare function:
override func prepare(for segue: uistoryboardsegue, sender: any?) { if (segue.identifier == "loginsegue") { if let token = sender as? string{ let mainpagevc = segue.destination as! mainpageviewcontroller mainpagevc.token = token } }
basically need perform segue after retrieve token.
Comments
Post a Comment