UINavigationController Push Views

Sorry - this might be a simple question, I'm new to iPhone development and still hug around Views and ViewControllers.

I have a NavigationViewController and I can click Views using the following method in the RootViewController which is associated with the Bar button item:

- (IBAction)switch:(id)sender {
        NSLog(@"Swith...");
        LibraryViewController *varLibraryViewController = [[LibraryViewController alloc] initWithNibName:@"LibraryViewController" bundle:nil];
        [[self navigationController] pushViewController:varLibraryViewController animated:YES];
    }

      

I want to call this same method from a button on the same view that is currently being viewed. Basically, I want the "Bar" button to be on the top call to the same method as the button on the view. I was wondering how to call a method on a ViewController from a view loaded from that viewController. Hope this makes sense.

Do I need to instantiate RootViewController? I would have thought this would already be created. Thank.

0


source to share


3 answers


Your RootViewController must have its own xib file. In this xib RootViewController is represented by an object named "File Owner". You can bind buttons on the view to the file owner the same way you can bind things to the RootViewController in the MainMenu.xib.



+1


source


By the way, the code you pasted is leaking your library controller. You need to either explicitly release it after clicking, or auto-update it when you create it.



+4


source


You want to declare your method as IBAction in your header file:


- (IBAction) myMethod: (id) sender;

      



Save the title, then switch to Interface Builder. Right click on the Bar button and drag it from the tag selector

to the view controller object (possibly the file owner). When you release, you should be presented with a pop-up menu of available actions and myMethod

select.

If you do not get this pop-up window, you may need to make sure that your File Owner class is set correctly: select File Owner in the file window, then choose Tools> Identity Inspector from the menu. In the inspector, enter the view controller class in the Class box.

+1


source







All Articles