I’m trying to make that when the user press a tabbar item an UIAlertView gets called, asking if really wants to change the actual tab, the problem is that the UIAlertView doesn’t stop the code until getting the answer, the code keeps running and depending on the previous value change the viewcontroller or not, not the actual.
I’ve tried to wait to the answer with a while, but the screen only gets darker and the alert didn’t popup. I also read this post pause code execution until UIAlertview, I tried but i was unable to make it work, can someone help, thanks!
- (BOOL) tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController{
if (([self Myfunction]) && (viewController != [tabBarController.viewControllers objectAtIndex:0])){
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"text1" message:@"text2" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
[alert show];
[alert release];
return boolean_var;
}
return YES;}
- (void)alertView:(UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) [self setBoolean_var:NO];
else [self setBoolean_var:YES];}
Identify which view controller that you need to show alert for and save it in
candidateViewControllerand returnNOto delay the switch. Based on the response on the alert view, you should change it.The last method assumes few things. Your tab bar controller is referenced by
self.tabBarControllerand that you were settingboolean_varto return it to the earlier method. Alert view is non blocking in that method so usingboolean_varis pointless.