How to Link a Static Storyboard UITable cells to another Storyboard
This problem has plagued me for quite some time. But never got around to solving it. I noticed there has been questions on the web asking for a solution. I've tried to respond to every thread out there, but I felt making a separate post may help as well.
The reason like many people involves building our app primarily using storyboards. Which in theory would make sense! However Apple does a bad job at explaining that massive storyboards will cause memory issues.
In my case I've run into a problem where I have roughly 200 "scenes/controllers in one storyboard. This causes massive delay and eats up my Memory in Xcode. So my thought was since all of these link to one UITableView. Why not be able to split up the scenes/controllers into separate storyboards and link them accordingly?
The problem now is I have static cells I've created in storyboard mode. So there are 30 Rows inside of this UITable.
How can I call each row out of the 30, and have them link to a separate storyboard???
Well the solution is actually incredibly simple!
You can download the xcode project here:
Below is the code needed..
In your MainStoryboard Controller
- (UITableViewCell *)tableView:(UITableView*)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{UITableViewCell *cell = [supertableView:tableViewcellForRowAtIndexPath:indexPath];
cell.accessoryType = UITableViewCellAccessoryNone;
NSUInteger row = [indexPath row];
if (row == 1)
{
NSLog(@"sameboard1loaded");
}
if (row == 2)
{
NSLog(@"sameboard2loaded");
}
if (row == 3)
{
NSLog(@"sameboard2loaded");
}
return cell;
}
Above, is more a test to prove that it detects the table and cells once its loaded. (Don't necessarily need it)
Below you will need. And that should be it! Obviously Link everything correctly on the storyboard etc. Code is a bit dirty, but it works.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
if (row == 0)
{
NSLog(@"sameboard1");
}
if (row == 1)
{
NSLog(@"sameboard2");
}
if (row == 2)
{
NSLog(@"differentboard");
UIStoryboard *storyboard1 = [UIStoryboardstoryboardWithName:@"storyboard1"bundle:nil];
UIViewController *MainStoryboard = [storyboard1 instantiateInitialViewController];
[self.navigationControllerpushViewController:MainStoryboard animated:(YES)];
}
[self.tableView reloadData];
}