Question

I have an app which displays a simple tableview and I wanted to add the SWRevealViewController as well.

In my appDelegate, before I added the SWReveal VC, I was setting my tableViewController like so...

In didFinishLaunchingWithOptions:

STRTableViewController *tableViewController = [(UINavigationController *)self.window.rootViewController viewControllers][0];
self.delegate = tableViewController;

and then again in the below method:

- (void)loadTableViewData
{
   UINavigationController *navVC = (UINavigationController *)self.window.rootViewController;
   STRTableViewController *tableVC = navVC.childViewControllers[0];
   [tableVC loadTableData]
}

Obviously when I put the SWRevealViewController to the front of the line, this no longer works as it is now trying to call loadTableData from the wrong view controller.

I've tried several ways and keep coming up short. How do I go about accessing the tableViewController now that it is not the first view controller?

If you need more code or logs or anything I'll be happy to post additional info. I have a feeling the answer is right there, I just don't have the experience to see it.

Also, just to be clear, now in the storyboard it goes from Reveal View Controller to Navigation Controller (the tableview's nav VC/ sw_front) and also to the sw_rear VC. Before it simply started with the Navigation Controller.

Thanks!

Was it helpful?

Solution

There's a bunch of ways you can go about keeping a reference to this.

The simplest would be just to keep a reference to the view controller in the AppDelegate.m

So you add a property

@property (nonatomic, strong) STRTableViewController *tableViewController;

Then, whenever and wherever you are instantiating and setting that table view controller, just do something like:

AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
delegate.tableViewController = justCreatedTableViewController;

You'll need to #import "AppDelegate.h" to access the app delegate in other classes where you want to do this.

Then to access it you can just do something like:

- (void)loadTableViewData
{
   [self.tableViewController loadTableData]
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top