【发布时间】:2013-03-09 21:00:50
【问题描述】:
我是新手。 ViewController.m 中有一个按钮。当我按下按钮时,它必须导航到 SecondViewController 但 SecondViewController 没有出现。
并且在导航栏的SecondViewController处,会有“Back”按钮回到ViewController。你能告诉我我错过了什么吗?
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;
}
【问题讨论】:
-
是导航控制器中的第一个viewcontroller吗?
-
ViewController 是第一个 ViewController。 EnglishViewController是第二个ViewController
-
你应该用导航控制器包围 ViewController 以使其工作。我会回答
标签: iphone ios objective-c uinavigationcontroller uinavigationbar