Reputation: 119
How to go to viewcontroller after certain actions, like here:
func requestForAccessToken(authorizationCode: String) {
Alamofire.request(url, method: .post, parameters: parameters, encoding: JSONEncoding.default, headers: nil)
.responseJSON { response in
switch response.result {
case .success(let JSON):
let response = JSON as! NSDictionary
let accessToken = response.object(forKey: "access_token")!
UserDefaults.standard.set(accessToken, forKey: "LIAccessToken")
UserDefaults.standard.synchronize()
///here...
DispatchQueue.main.async(execute: { () -> Void in
// self.dismiss(animated: true, completion: nil)
let secondViewController: LoginViewController = LoginViewController()
self.present(secondViewController, animated: true, completion: nil)
})
case .failure(let error):
print("Request failed with error: \(error)")
}
}
}
I create vc in storyboard and make vc class file. Maybe I must make something other.
Upvotes: 1
Views: 1088
Reputation: 2914
If you are creatung a viewController
in storyboard
then you have to instantiate it with storyboard. Try this:
DispatchQueue.main.async(execute: { () -> Void in
let secondViewController = UIStoryboard(name:"LoginViewController", bundle: nil.instantiateViewControllerWithIdentifier("LoginViewController") as? LoginViewController
self.present(secondViewController, animated: true, completion: nil)
})
Hoping that you have named your storyboard as LoginViewController
and provided with storyboardID
as LoginViewController
Upvotes: 1