Ramesh Kumar Ramesh Kumar - 10 months ago 111
Objective-C Question

I want to move to next screen after getting response from twitter login

not able to to move to next screen as soon as I get response from twitter login.

[[Twitter sharedInstance] logInWithCompletion:^(TWTRSession *session, NSError *error) {
if (session) {
NSLog(@"signed in as %@", [session userName]);
NSString *userStr = [session userName];
NSString *userStr1 = [session userID];
UIStoryboard *strory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

phoneViewController *editobj = [strory instantiateViewControllerWithIdentifier:@"phoneViewController"];

[self presentViewController:editobj animated:YES completion:nil];
} else {
NSLog(@"error: %@", [error localizedDescription]);
}
UIStoryboard *strory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

phoneViewController *editobj = [strory instantiateViewControllerWithIdentifier:@"phoneViewController"];

[self presentViewController:editobj animated:YES completion:nil];

}];

Answer Source

You should execute all interface-related tasks only in the main queue. So simply dispatch your view controllers transition to it:

[[Twitter sharedInstance] logInWithCompletion:^(TWTRSession *session, NSError *error) {
    if (session) {
        NSLog(@"signed in as %@", [session userName]);
        NSString *userStr = [session userName];
        NSString *userStr1 = [session userID];

        dispatch_async(dispatch_get_main_queue(), ^{
            UIStoryboard *strory = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

            phoneViewController *editobj = [strory instantiateViewControllerWithIdentifier:@"phoneViewController"];

            [self presentViewController:editobj animated:YES completion:nil];
        });
    } else {
        NSLog(@"error: %@", [error localizedDescription]);
    }
}];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download