在块中推送视图

时间:2014-08-08 19:01:13

标签: ios view block pushviewcontroller

我在完成块中调用一个视图推送方法并且它不起作用,通常当我从另一个非块方法调用它时它起作用。我认为它与线程有关但我无法解决,我该怎么办?

这是我的推送方式:

-(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];

 }];

1 个答案:

答案 0 :(得分:3)

将方法调用移至主线程,并且在修改后不要忘记同步用户默认值,如下所示:

dispatch_async(dispatch_get_main_queue(), ^{
    [[NSUserDefaults standardUserDefaults] setObject:authToken forKey:@"token"];
    [[NSUserDefaults standardUserDefaults] syncronize];
    [self goToVenues];
});