2015-10-16 18 views
0

我在我的應用程序的選項卡。我顯示視圖controller.in一個選項卡中的一個選項卡我有一個視圖控制器,其中包含填寫表單的文本字段。所以,如果用戶填寫表格&不保存它然後我想要顯示一個警報。如果你點擊沒有警報,那麼它應該移動到下一個屏幕,否則不行。我已經嘗試了以下工作,但它顯示每個屏幕上的警報。在移至iOS中的下一個標籤之前顯示警報?

-(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; 

     } 


} 

回答

1
-(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.. 

    } 
} 
+0

做什麼用標籤的指數DIO ???我需要顯示只警報當前視圖控制器 – Techiee

+0

等待...我更新我的答案 –

+0

嘗試此代碼...如果不工作,然後添加代碼viewwilldisappear .. –

相關問題