Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 在viewController的一个实例中,PerformScheue(withIdentifier)失败_Swift_Swift3 - Fatal编程技术网

Swift 在viewController的一个实例中,PerformScheue(withIdentifier)失败

Swift 在viewController的一个实例中,PerformScheue(withIdentifier)失败,swift,swift3,Swift,Swift3,我有一个viewController来处理对用户进行oAuth API身份验证。如果user.defaults中有存储的令牌,则此块将运行 FRDStravaClient.sharedInstance().fetchCurrentAthlete(success: { (StravaAthlete) -> Void in self.performSegue(withIdentifier: "AuthorizeSuccessfulSegue", sender: StravaAthlet

我有一个viewController来处理对用户进行oAuth API身份验证。如果user.defaults中有存储的令牌,则此块将运行

FRDStravaClient.sharedInstance().fetchCurrentAthlete(success: { (StravaAthlete) -> Void in
    self.performSegue(withIdentifier: "AuthorizeSuccessfulSegue", sender: StravaAthlete.self)
}, failure: { (Error) in
    //some failure stuff
})
segue将被触发,用户将转到应用程序的其余部分

但是,如果用户在授权后返回应用程序时需要登录,则此块将运行:

FRDStravaClient.sharedInstance().exchangeToken(forCode: code,
success: { (response: StravaAccessTokenResponse? ) in
    self.performSegue(withIdentifier: "AuthorizeSuccessfulSegue", sender: response?.athlete)
}, failure:{ (error) -> Void in
    self.showAuthFailedWithError(error: (error?.localizedDescription)!)
    print(error!)
})
这会导致应用程序崩溃,错误为:“Receiver()没有标识符为“AuthorizesSuccessfulSegue”的segue”


两个成功块使用在Interface Builder中正确设置的相同标识符。self正在引用AuthViewController。为什么一个在工作,另一个在崩溃?

问题是第一个函数发生在
viewdiload
中,而第二个函数发生在从Safari返回并授权应用程序时appDelegate调用的VC函数中。我正在实例化一个新的AutViewController,而不是获取当前实例。

问题是第一个函数发生在
viewDidLoad
中,而第二个函数发生在从Safari返回并授权应用程序时appDelegate调用的VC函数中。我正在实例化一个新的AutViewController,而不是获取当前实例。

您是否尝试过让发送者
自己
?另外,如果这是一个异步请求,您应该在调度块中执行segue,如
DispatchQueue.main.async{self.performsgue…}
我觉得这没问题。你确定这两个块在同一个视图控制器中吗?@Pierce在发布之前,我尝试了发送方的几种变体,并加入了
DispatchQueue.main.async
,但它没有改变任何东西(我也尝试了一次),两者都是异步函数。你尝试过让发送方
self
?另外,如果这是一个异步请求,您应该在调度块中执行segue,如
DispatchQueue.main.async{self.performsgue…}
我觉得这没问题。你确定这两个块在同一个视图控制器中吗?@Pierce在发布之前,我在发送方上尝试了几种不同的方法,并加入了
DispatchQueue.main.async
,但它没有改变任何东西(我也尝试了一次),它们都是异步函数。