I would suggest that don't create cell in Storyboard and connect it. Instead leave empty table in storyboard and create cell using code. You can create custom cell by subclassing UITableViewCell
.
In storyboard you just link table view with all view controller using segue and give it proper identifier name.

Now implement all delegates methods of UITableView
. Override -tableView:didSelectRowAtIndexPath:
method and on row selection perform segue for specific row.
Example:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
switch (indexPath.row) {
case 0:
[self performSegueWithIdentifier:@"BasicCoreDataSegue" sender:self];
break;
default:
break;
}
}
Here in above case if you select first row it will push view controller which is connect with BasicCoreDataSegue
segue in Storyboard, you can compare it with image.
Using similar way create other segues and call them in didSelectRowAtIndexPath
method in different switch case.
Also If you want to pass any values to push controller, override below method:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
if ([[segue identifier] isEqualToString:@"BasicCoreDataSegue"]) {
// Get reference to the destination view controller
TextViewController *vc = [segue destinationViewController];
vc.textView.text = "Hello";
}
}
Edit:
Above code works for common controller. Now you don't need to create more segues also in didSelectRowAtIndexPath
method set Intermediate controller segue.
Use [self.tableView indexPathForSelectedRow]
method to get selected row in prepareForSegue
method.
For Example:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self performSegueWithIdentifier:@"BasicCoreDataSegue" sender:self];
}
Now when prepareForSegue
is called then set integer value for Intermediate controller.
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// You can get selected row using below line
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
// Pass the selected object to the new view controller.
if ([[segue identifier] isEqualToString:@"BasicCoreDataSegue"]) {
// Get reference to the destination view controller
IntermediateController *vc = [segue destinationViewController];
vc.selectedIndex = indexPath.row;
}
}
In above code selectedIndex
is a integer variable which is used to track that which row is selected.
Now in Intermediate controller in -viewDidLoad()
use switch case to get controller object which you want from row selection and add its view as a subview in Intermediate Controller.
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard"
bundle: nil];
TextViewController *controller = (TextViewController*)[storyBoard
instantiateViewControllerWithIdentifier: @"TextViewControllerId"];
[self.topView addSubview:controller.view];