我正在尝试从按钮推送视图。该方法在点击时被调用,但视图不会被推入导航控制器。以下是按钮点击的代码:
- (IBAction)aboutButtonTapped:(id)sender {
NSLog(@"dashBoardButtonTapped");
if (self.aboutView == nil) {
self.aboutView = [[About alloc] initWithNibName:@"About" bundle:nil];
[self.navigationController pushViewController:self.aboutView animated:YES];
}
else {
[self.navigationController pushViewController:self.aboutView animated:YES];
}
}
我想要做的是,当我登录到我的应用程序时,会出现一个带有按钮的选项视图。每个按钮都必须按下视图。下面是ViewController.m文件中的代码,它调用optionsView:
self.optionsView = [[Options alloc] initWithNibName:@"Options" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:self.optionsView];
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
delegate.window.rootViewController = self.navigationController;
请告诉我这件事我做错了什么?
答案 0 :(得分:1)
您必须在appDelegate方法中添加一个UIViewcontroller
,然后将其RootViewcontroller
UInavigationController
加入其中: -
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[yourViewcontroller alloc] initWithNibName:@"yourViewcontroller" bundle:nil];
self.navController=[[UINavigationController alloc]initWithRootViewController:self.viewController];
self.window.rootViewController = self.navController;
[self.window makeKeyAndVisible];
return YES;
}
然后你不需要应用每个类创建新的UInavigationController你只需要你的pust推送方法和你的视图按你想要的推动。 :)