我是新手。ViewController.m 中有一个按钮。当我按下按钮时,它必须导航到 SecondViewController 但 SecondViewController 没有出现。
并且在导航栏的SecondViewController处,会有“Back”按钮返回ViewController。你能告诉我我错过了什么吗?
视图控制器.m:
-(IBAction)buttonPressed:(id)sender
{
EnglishViewController *v = [[[EnglishViewController alloc]
initWithNibName:@"EnglishViewController"
bundle:nil]
autorelease];
[self.navigationController pushViewController:v animated:TRUE];
}
AppDelegate.m:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
解决方案(取决于@George 的回答):
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];
UINavigationController *navCon =[[[UINavigationController alloc]
initWithRootViewController:self.viewController]
autorelease];
self.window.rootViewController =navCon;
[self.window makeKeyAndVisible];
return YES;
}