1

我想制作一个简单的导航控制应用程序,其中有两个视图控制器(ViewControllerViewController2)。我有一个按钮ViewController,当我按下按钮时,我希望它转到另一个视图。问题是按钮不起作用。我也尝试过UIViewController,但也没有以这种方式工作。

AppDelegate.m

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.

    ViewController *vc1 = [[ViewController alloc]init];

    UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:vc1];

    self.window.rootViewController = nav;


    [self.window makeKeyAndVisible];
    [self.window addSubview:nav.view];
    return YES;
}

ViewController.m

- (IBAction)myButton:(id)sender {

    ViewController *vc2 = [[ViewController alloc]init];

    [[self navigationController]pushViewController:vc2 animated:YES];
}

在此先感谢您的帮助

4

1 回答 1

0

如果您在 ViewController1 中使用情节提要导入 ViewController2 并为其提供情节提要 ID“view2”:

  ViewController2 *vc2 = (ViewController2 *)[self.storyboard instatiateViewControllerWithIdentifier:@"view2"];
  [self.navigationController pushViewController:vc2 animated:YES];
于 2013-07-29T15:18:44.793 回答