Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a left view controller (sliding menu controller) in use for example called LeftMenuTableViewController.

When a user logs out a modal view controller is displayed but the tableview controller stays in the background. When they login the controller is dismissed and the others shown again.

How do I do the following: 1. Check that the table view controller does exist on the stack. 2. Create a pointer to this controller on the stack without alloc init (creating another one)

I need a pointer to it so that I can load the tableView reloadData method once logged in, if it exists on stack.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

There are several different ways to do this. It just depends on the look you want to achieve.

I think the neatest way to do this would be to use a UIViewController with two container views, then embed your login view controller in one container view, and your tableview controller in the other container view.

After you create references to these containers in their view controller, you can animate each container view however you want to, such as sliding out the login view then hiding it. This way, your "master" view controller will always have a reference to both your tableView controller and your login view controller.

If you don't want to move away from the method of using modal transitions between view controllers, here is what I tell you:

There doesn't exist a "stack" of view controllers anywhere as you describe it. You will have to create one yourself, probably in the app delegate.

In order to do this, you will need to create a reference to the view controller you need a pointer for in your app delegate, make a property for it, and synthesize it. It would look something like this:

MyAppDelegate.h

@interface MyAppDelegate : UIResponder
{
    MyViewControllerClass *myViewController;
}
@property (nonatomic) MyViewControllerClass *myViewController;

MyAppDelegate.m

@synthesize myViewController;

Then, in the viewDidLoad method of the view controller....

[[[UIApplication sharedApplication] delegate] setMyViewController:self];

After you set this up, you can check to see if a pointer to that view controller exists by saying

if([[UIApplication sharedApplication] delegate].myViewController)
{
    //does exist
}
else
{
    //does not exist
}

To access a method on that view controller, just say something like

[[[UIApplication sharedApplication] delegate].myviewController performMyMethod]

Hope that helps you.

share|improve this answer
    
The actual answer I was looking for was this : MESLeftMenuTableViewController tvc = (MESLeftMenuTableViewController)self.slidingViewController.underLeftViewControl‌​ler; [tvc.tableView reloadData]; -- This gave me a pointer to the view controller. I was looking to find out how to create the pointer to the controller that is already created. If you have any other information on how to create pointers to View Controllers that have already been created and are on the stack ... i.e the navigation controller stack of modal stack or custom stack that would be of use to me :) –  StuartM May 9 '13 at 21:30
    
edited with another way to set this up, closer to what I believe you are looking for. –  darkfoxmrd May 9 '13 at 21:44
    
Thanks, the answer that I used was in my comment, but I could definitely use this approach going forward. I guess I could set the delegate on another controller too as opposed to using the app delegate. –  StuartM May 10 '13 at 8:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.