how to create a uiview with segues, which is used by several UIViewControllers in the storyboard


Basically what I want to do is to include UIView to multiple UIViewControllers on storyboard. I could include the uiview, but segues in the UIView doesn't work. I have a storyboard something like this:

I have a tab controller with 2 UIViewControllers First and Second. And I have a separated UITableViewController with two another UIViewControllers A and B, connected with segues.

I could add the table view into First and Second views as a subview, but when I tap cell it doesn't go to next screen A or B. I sort of figured out why it didn't work, but just can't figure the best way to accomplish this.

Is there any good way to do this? I'm new to storyboard but have been developing iOS app for a while.


The way I add the tableViewController to each View is following:

self.tableViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"theTableViewController"];
[self.view addSubview:_tableViewController.tableView];

When a cell in the table view is tapped, prepareForSegue:segue:sender is invoked, but no push to navigation controller since the table view controller is sitting in each view controller as just a subview


I posted my test project here

There are 2 methods you can try .

1.Create a segue between the tableview cell and next view controller directly. What I want to emphasize is the fact that do not create segue between the tableview or view and the next view controller,unless trying the method below.

2.Add this code to your tableview controller :

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    if ([indexPath row]) {
        [self performSegueWithIdentifier:@"segueToB" sender:self];
    }else {
         [self performSegueWithIdentifier:@"segueToA" sender:self];