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.
source to share
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.
source to share