At this point I’m pretty frustrated but I’m sure it is something I’m missing. In this code my segue to my new viewController is showing up after the rest of the function is executed. How do I get my viewController to be the code being executed? Basically stop the tweetText function from happening until that view is closed I’m trying to give the user an option to select a twitter account if there is more than one. I have tried many different ways. In Apples own example code they suggest to give the user an option but give nothing on how to do it without blowing through the rest of the code.
Here is the code:
[accountStore requestAccessToAccountsWithType:accountType withCompletionHandler:^(BOOL granted, NSError *error) {
if(granted) {
dispatch_sync(dispatch_get_main_queue(), ^{
// Get the list of Twitter accounts.
self.accountsArray = [accountStore accountsWithAccountType:accountType];
if([self.accountsArray count] > 1 /* Check method to see if preference is still a valid account */) {
// Display user accounts if no preference has been set
[self performSegueWithIdentifier:@"TwitterAccounts" sender:self.accountsArray];
[tweet tweetText:tweetString account:self.twitterAccount type:AchievementTweet];
} else {
[tweet tweetText:tweetString account:[self.accountsArray lastObject] type:AchievementTweet];
}
});
} else {
[tweet performSelectorOnMainThread:@selector(displayText:) withObject:[NSNumber numberWithInt:403] waitUntilDone:NO];
}
}];
I am a little confused on what is your purpose but you got 2 options.
There is really no need for GCD here.
I would suggest to register for a notification which will perform your second action once your first action has been accomplished. (Similar to how apple handles the image picker, on their code they inform of when the picture has finally been saved to execute another function).
The other way is using delegates, on this approach you would put the second part of the code on a separate function, then declare that controller as the delegate of the viewcontroller you want executed first, then after whatever you want acomplished is done on the viewcontroller you would ask the delegate to perform the second code and if necessary ask the delegate to close the view as well.