繁体   English   中英

在UINavigationController中,按钮不适用于pushViewController

[英]In UINavigationController, button doesn't work with pushViewController

我想制作一个简单的导航控制应用程序,其中有两个视图控制器( 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];
}

在此先感谢您的帮助

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

  ViewController2 *vc2 = (ViewController2 *)[self.storyboard instatiateViewControllerWithIdentifier:@"view2"];
  [self.navigationController pushViewController:vc2 animated:YES];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM