Reputation: 285
I am using Storyboard and trying to return back to a previous screen when a certain condition is met. IE, the username is not found on login.
Essentially, the user types in their info and presses a button. If the info is incorrect or not found, I show a UIAlertView message to inform them of the incorrect info. Due to the order things are done, the screen transition happens on the button press before I have checked any data with the server. So I can't halt the screen change before I check.
I am checking for the user's button press in the UIAlertView for signal to go back with this method ..
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
[self.navigationController popViewControllerAnimated:YES];
}
I am trying to use the one line in that method to return to the previous screen but nothing happens. I assume storyboards work differently but I don't know the syntax to return to the previous screen with them.
Thanks.
Upvotes: 2
Views: 940
Reputation: 8593
I would guess your self.navigationController
is nil, which makes your method a no-op.
Upvotes: 0
Reputation: 22939
If your storyboard pushes a view controller then you can always programatically pop it. this is not a problem. The problem here is that the UIAlertView is shown using an animation and therefore you can't perform another animation in one go.
So you have two options. Popping the view controller without animation should work but then the user might not realize where he is getting to.
You can put the call that pops the viewcontroller into a helper method and call this methd like this: [self performSelector:@selector(myPopHelperMethod:) withObject:nil afterDelay:0.8f]
. This should pop your view controller after 0.8 seconds which is enough to let the UIAlertView finish its animation.
Upvotes: 1