I have a project using JASidePanels with a left menu containing a UITableView to change the center panel's contents.
As I want the ability to be able to deep link to my controllers via a custom URL scheme, I have moved the view switching functionality into the AppDelegate.m file as part of the handleOpenURL: function. With this, I updated the didSelectRowAtIndexPath: function of the Menu Controller to call the custom URL like so:
- (void)tableView:(UITableView *)aTableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSInteger index = indexPath.row;
NSDictionary *item = self.menu[index];
NSURL *myURL = [NSURL URLWithString:item[@"url"]];
[[UIApplication sharedApplication] openURL:myURL];
}
The handleOpenURL: function of the AppDelegate when using .xibs instead of storyboard looks like:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
if ([[url host] isEqualToString:@"goto"]) {
for (int i = 0; i < [self.leftMenuViewController.tableView
numberOfRowsInSection:0]; i++) {
[self.leftMenuViewController.tableView
deselectRowAtIndexPath:[NSIndexPath indexPathForRow:i
inSection:0] animated:NO];
UITableViewCell *deselectedCell = [self.leftMenuViewController.tableView
cellForRowAtIndexPath:[NSIndexPath indexPathForRow:i
inSection:0]];
deselectedCell.backgroundColor = [UIColor clearColor];
}
...
}
}
This works as desired, deselecting and formatting all rows in the UITableView on the Menu Controller when not using storyboards and creating the interfaces in xib files.
My problem comes when using Storyboards. How am I able to access the (UITableView *)tableView from the MenuViewController from within the AppDelegate when it was instantiated from within a storyboard by another controller (SidePanelController)?
I am setting up the storyboard with the following code within my didFinishLaunchingWithOptions: function:
self.storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:[NSBundle mainBundle]];
self.viewController = [storyboard instantiateInitialViewController];
self.window.rootViewController = self.viewController;
so I need to access the already instantiated instance of MenuViewController rather than create a new instance of the controller. I have tried to access the tableView via:
SidePanelController *panelController = (SidePanelController *)self.window.rootViewController;
UIViewController *menuViewController = (MenuViewController *)panelController.leftPanel;
UITableView *menuTableView = (UITableView *)menuViewController;
but not having much luck. Is it possible to programmatically retrieve a UITableView out of a view instantiated in a storyboard?
Thanks in advance
Ash