Tim
Tim

Reputation: 13258

Instance of the ViewController

I want to access the current ViewController.

I have a TabBar with a NavBar and there is a ViewController in it. In this ViewController (TableView) I made a "pushViewController" to a new ViewController.

How can I access this one in another class. If I do:

[(MyTestDetailViewController *)[[(UINavigationController *) [appDelegate.myTabBarController selectedViewController] viewControllers] objectAtIndex: 0] myMethod:testArg1 withArgs:testArg2];

the method of the first ViewController is called (it also have the same myMethod:withArgs in it), but not this one of the current view (the pushed one).

What's wrong here? Does anyone know?

Thanks a lot in advance & Best Regards.

Upvotes: 1

Views: 412

Answers (1)

MrMage
MrMage

Reputation: 7496

The UINavigationController implements the visibleViewController property for this purpose.

Try this:

[(MyTestDetailViewController *)[(UINavigationController *)[appDelegate.myTabBarController selectedViewController] visibleViewController] myMethod:testArg1 withArgs:testArg2];

Upvotes: 2

Related Questions