如何在某些操作后转到viewcontroller,例如:
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)")
}
}
}
我在storyboard中创建vc并制作vc类文件。也许我必须做别的事。
答案 0 :(得分:1)
如果您是viewController
中的storyboard
,那么您必须使用故事板进行实例化。试试这个:
DispatchQueue.main.async(execute: { () -> Void in
let secondViewController = UIStoryboard(name:"LoginViewController", bundle: nil.instantiateViewControllerWithIdentifier("LoginViewController") as? LoginViewController
self.present(secondViewController, animated: true, completion: nil)
})
希望您已将故事板命名为LoginViewController
,并将storyboardID
作为LoginViewController
提供