Objective c 从一个视图导航到另一个视图

Objective c 从一个视图导航到另一个视图,objective-c,cocoa-touch,uiviewcontroller,Objective C,Cocoa Touch,Uiviewcontroller,主要:xxxVieController 第二个选项是:OptionViewController 在xxxView控制器中,我有 .h @interface iMetroAlertViewController : UIViewController { IBOutlet UIButton *option; } -(IBAction) goToOption; 及 当然,会创建选项ViewController.xib、.m和.h 当我按下按钮时,什么也没有发生链接完成了,因为我有一个NSL

主要:xxxVieController 第二个选项是:OptionViewController

在xxxView控制器中,我有

.h
@interface iMetroAlertViewController : UIViewController {

    IBOutlet UIButton *option;
}

-(IBAction) goToOption;

当然,会创建选项ViewController.xib、.m和.h

当我按下按钮时,什么也没有发生链接完成了,因为我有一个NSLog


我不明白它为什么不工作,因为您没有导航控制器,所以调用self.navigationController返回nil。

首先您必须创建导航控制器

- (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;
}

返回后不会执行任何语句。我在哪里编写此代码?您所谓的RootViewController是我的xxxViewController还是OptionViewController?谢谢你的xxxViewController写下这个。。。在optionViewController中编写您的问题中提到的代码…有关我在iMetroAlertController xxxViewController中编写的uinavigation控制器的基础知识,请参阅此链接:-BoolaApplication:UIApplication应用程序完成启动时使用选项:NSDictionaryLanchOptions{iMetroAlertViewController*mainMenuVC=[[iMetroAlertViewController alloc]init];navigationController=[[UINavigationController alloc]initWithRootViewController:mainMenuVC];[self.window addSubview:navigationController.view];[self.window makeKeyAndVisible];返回YES;}它给出了未声明的取消错误“navigationController”
- (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;
}