views:

244

answers:

3

I have an iPhone app which has a tabBarController as the root view controller in mainwindow.xib.

One of the tabs has a class of UINavigationController and its View is loaded from an external Nib file currently called secondView.xib

How can I get a UIBarButtonItem which is on the NavigationController in the mainwindow.xib file to trigger methods in its child view, secondView.h/m view controller?

+2  A: 

I think you need to get access to the app delegate (secondView app del) in the MainWindow and then call methods on that. Er, send messages to that object.

Mr-sk
+1  A: 

Completely re-did the answer, since I misunderstood your question.

In the viewDidLoad method of the UIViewController add:

UIBarButtonItem *myButton = [[UIBarButtonItem alloc] init]; // do some initialization here
self.navigationItem.leftBarButtonItem = myButton;
[myButton release];

The designated initializer for a UIBarButtonItem lets you set the method that's called when it's pressed.

kubi
@kubi It's actually the other way round I want. My tabBarController has a tab which has a class of navigation controller. I want to press a button on the upper left corner of the navigation controller which triggers a method in the child view controller
Griffo
A: 

Actually, all I needed to do was double click the subview within the navigation controller so it had focus, then ctl-drag it to the button I had placed on the bar and I could select the method from the drop down list. Apologies if I wasted anyones time, thanks for the help anyway. Both helped me look harder at what I was doing.

Griffo