[英]In UINavigationController, button doesn't work with pushViewController
我想制作一個簡單的導航控制應用程序,其中有兩個視圖控制器( ViewController
和ViewController2
)。 我在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.