我的应用程序中有选项卡。在一个选项卡中,我显示了一个 View Controller 。在其中一个选项卡中,我有一个 View Controller ,其中包含用于填写表单的文本字段。因此,如果用户已填写表单但未保存,则我想显示一个警报。如果您在警报上单击否,那么它应该移至下一个屏幕,否则不会。我已经尝试了以下它有效但它在每个屏幕上都显示警报。
-(BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
{
if ([self isAllDataValid])
{
back_alert=[[UIAlertView alloc]initWithTitle:@"Warning" message:@"Are you sure you want to delete your data?" delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
[back_alert show];
return NO;
}
else
{
return YES;
}
}
最佳答案
-(void)tabBarController:(UITabBarController *)theTabBarController didSelectViewController:(UIViewController *)viewController
{
NSUInteger indexOfTab = [theTabBarController.viewControllers indexOfObject:viewController];
NSLog(@"Tab index = %u (%u)", indexOfTab);
if (indexOfTab == 1)
{
//add your alert..
}
}
关于ios - 在移动到 iOS 中的下一个选项卡之前显示警报?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33163310/