ios - 在移动到 iOS 中的下一个选项卡之前显示警报?

标签 ios objective-c uitabbarcontroller

我的应用程序中有选项卡。在一个选项卡中,我显示了一个 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/

相关文章:

iOS:未调用 didSelectRowAtIndexPath

iphone - 标签栏项目图像和 selectedImage

ios - Swift,继续从选项卡栏 Controller 中 Split View Controller

objective-c - 复制自定义对象

iphone - iOS 中读取设备唯一 ID 的代码应该放在哪里?

ios - 主线程上的 AFNetworking 和 NSURLConnection

iphone - 将图像添加到 iPhone 导航栏

iphone - 我正在尝试使用以下代码自定义 UITabbar ,但没有任何运气

ios - 快速获取 ScrollView 内触摸的位置(坐标)

ios - 当应用程序处于后台或被杀死时如何定期获取新位置