How do I segue to 2 views based on a Segmented Control and an Add button?

后端 未结 2 2025
情深已故
情深已故 2020-12-30 17:08

I have a segmented control in the header of a navigation controller, I want to add an object to a table view controller thats also in this navigation controller.

He

相关标签:
2条回答
  • 2020-12-30 17:35

    You make what I call "generic" segues that are not associated with an action/trigger. See my answer here: How to make and use generic segue

    Make 2 of these segues, then in your IBAction method for your segmentedControl call performSegueWithIdentifier:. For example:

    - (IBAction)segmentCtrlChanged:(id)sender {
     UISegmentedControl *seg = sender;
     if (seg.selectedSegmentIndex == 0) 
       [self performSegueWithIdentifier:@"segue1" sender:self];
     else if (seg.selectedSegmentIndex == 1) 
       [self performSegueWithIdentifier:@"segue2" sender:self];
    }
    
    0 讨论(0)
  • 2020-12-30 17:43

    You only need one segue in your storyboard. in you viewcontroller, add the

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    

    method, and use switch to decide which segment is being selected.

    e.g.

    - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
    {
        switch (self.segmentedButton.selectedSegmentIndex)
        {
              case 0:
              {
                    UIView1 *view1 = (UIView1 *)segue.destinationViewController;
                    // do other customization if needed
                    break;
              }
              case 1:
              {
                    UIView2 *view2 = (UIView2 *)segue.destinationViewController;
                    // do other customization if needed
                    break;
              }
              default:
                   break;
        }
    }
    

    http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html

    http://developer.apple.com/library/ios/#documentation/uikit/reference/UIStoryboardSegue_Class/Reference/Reference.html#//apple_ref/doc/c_ref/UIStoryboardSegue

    0 讨论(0)
提交回复
热议问题