我在完成块中调用一个视图推送方法并且它不起作用,通常当我从另一个非块方法调用它时它起作用。我认为它与线程有关但我无法解决,我该怎么办?
这是我的推送方式:
-(void)goToVenues{
venuesList *venuesList = [self.storyboard instantiateViewControllerWithIdentifier:@"VenuesList"];
[self.navigationController pushViewController:venuesList animated:YES];
}
这是完成块:
[FSOAuth requestAccessTokenForCode:accessCode
clientId:clientID
callbackURIString:callbackURI
clientSecret:clientSecret
completionBlock:^(NSString *authToken, BOOL requestCompleted, FSOAuthErrorCode errorCode) {
[[NSUserDefaults standardUserDefaults] setObject:authToken forKey:@"token"];
[self goToVenues];
}];
答案 0 :(得分:3)
将方法调用移至主线程,并且在修改后不要忘记同步用户默认值,如下所示:
dispatch_async(dispatch_get_main_queue(), ^{
[[NSUserDefaults standardUserDefaults] setObject:authToken forKey:@"token"];
[[NSUserDefaults standardUserDefaults] syncronize];
[self goToVenues];
});