簡體   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