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