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
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];
}
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