2012-07-26 16 views
0

想知道如何在tabbarbutton中顯示動作表後調用segue。如何在tapbarbutton中點擊uiactionsheet後調用segue

我在應用程序委託中完成了所有這些工作,如果appdelegate不是一個好的做法。我應該在哪裏添加這些代碼行?

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController { 

    NSInteger choice = 1; // --> index of the view controller that should "act as button" 
    if (viewController == [tabBarController.viewControllers objectAtIndex:choice]) 

     { 
      UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil 
                   delegate:self 
                 cancelButtonTitle:@"Cancel" 
               destructiveButtonTitle:Nil 
                 otherButtonTitles:@"000", @"Car Accident",@"Home",@"Property", nil]; 
      sheet.tag = 0; 
      [email protected]"test"; 
      NSLog(@"tab tab"); 
       [sheet showInView:self.window]; 
       return NO; 

    } 


    NSLog(@"YES YES"); 
    return YES; 
} 


- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { 
    if(actionSheet.tag == 0) 
    { 

      if (buttonIndex == 0) 
      { 
       UIDevice *device = [UIDevice currentDevice]; 

       if ([[device model] isEqualToString:@"iPhone"]) 
       { 
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt:000"]]; 

       } else 
       { 
        UIAlertView *Notpermitted=[[UIAlertView alloc] initWithTitle:@"Alert" message:@"Your device doesn't support this feature." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
        [Notpermitted show]; 
       } 


      } 
      else if (buttonIndex == 1) 
      { 
       NSLog(@"Car Accident"); 
       //tried to call a segue here. 

      } 
      else if (buttonIndex == 2) 
      { 

       NSLog(@"YES YES"); 
      } 
      else if (buttonIndex == 3) 
      { 
       NSLog(@"YES YES"); 

      } 
     } 
} 

感謝您的閱讀和評論。

回答

0
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 

    // Do any additional setup after loading the view. 
    UITabBarController *tabController = (UITabBarController *)appDelegate.window.rootViewController; 
    tabController.selectedIndex = 0; 
    tabController.delegate = self; 
} 

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController { 

    NSInteger choice = 1; // --> index of the view controller that should "act as button" 
    if (viewController == [tabBarController.viewControllers objectAtIndex:choice]) 

    { 
     UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:nil 
                  delegate:self 
                cancelButtonTitle:@"Cancel" 
              destructiveButtonTitle:Nil 
                otherButtonTitles:@"000", @"Car Accident",@"Home",@"Property", nil]; 
     sheet.tag = 0; 
     [email protected]"Emergency"; 
     NSLog(@"tab tab"); 

     [sheet showInView:[self.view superview]]; 
     return NO; 

    } 


    NSLog(@"YES YES"); 
    return YES; 
} 


- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { 
    if(actionSheet.tag == 0) 
    { 

     if (buttonIndex == 0) 
     { 
      UIDevice *device = [UIDevice currentDevice]; 

      if ([[device model] isEqualToString:@"iPhone"]) 
      { 
       [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"telprompt:000"]]; 

      } else 
      { 
       UIAlertView *Notpermitted=[[UIAlertView alloc] initWithTitle:@"Alert" message:@"Your device doesn't support this feature." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 
       [Notpermitted show]; 
      } 


     } 
     else if (buttonIndex == 1) 
     { 
      NSLog(@"Car Accident"); 
      [self performSegueWithIdentifier:@"pushToCarView" sender:self]; 

     } 
     else if (buttonIndex == 2) 
     { 

      NSLog(@"YES YES"); 
     } 
     else if (buttonIndex == 3) 
     { 
      NSLog(@"YES YES"); 

     } 
    } 
} 
相關問題