Navigate from a view to another
The main: xxxVieContro开发者_StackOverflow社区ller and the second: OptionViewController
in xxxView controller I have
.h
@interface iMetroAlertViewController : UIViewController {
IBOutlet UIButton *option;
}
-(IBAction) goToOption;
and
.m
@implementation iMetroAlertViewController
-(IBAction) goToOption{
NSLog(@"Works");
OptionViewController *dvController = [[OptionViewController alloc] initWithNibName:@"OptionView" bundle:[NSBundle mainBundle]];
[self.navigationController pushViewController:dvController animated:YES];
[dvController release];
dvController = nil;
}
Of course a OptionViewController.xib, .m and .h are created...
When I push on the button, nothing happens (the link is done cause I have an NSLog
I don't understand why it doesn't work
It probably doesn't work because you don't have a navigation controller, so calling self.navigationController
returns nil
.
First you have to create the navigation controller
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
RootViewController *mainMenuVC = [[RootViewController alloc] init];
navigationController = [[UINavigationController alloc] initWithRootViewController:mainMenuVC];
[self.window addSubview:navigationController.view];
[self.window makeKeyAndVisible];
return YES;
}
精彩评论