0

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!

Christian
  • 336
  • 1
  • 4
  • 16

1 Answers1

1

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]
}
Dima
  • 23,484
  • 6
  • 56
  • 83
  • That did it! Thank you! That solved that problem of calling the right view, but now the table data is not loading in the view. The logs are showing that that data is being fetched so I'm sure it's just something with reloading the view after the user accepts location services. – Christian Mar 31 '14 at 20:55
  • I'm not sure what you mean but you should make a separate new question to get the best help :) – Dima Mar 31 '14 at 21:19
  • I added a new question here http://stackoverflow.com/questions/22773205/table-not-loading-data-after-adding-swrevealviewcontroller – Christian Mar 31 '14 at 22:13