views:

59

answers:

1

Hello!

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.

+2  A: 

The UINavigationController implements the visibleViewController property for this purpose.

Try this:

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

MrMage
Thanks a lot! This works.
Tim