我相信您已经在 AppDelegate 中声明了导航控制器并将导航控制器设置为根视图控制器。以防万一您还没有假设您从单个视图应用程序开始。
appdelegate.h
@interface AppDelegate : UIResponder <UIApplicationDelegate>
{
ViewController *objViewController;
UINavigationController *objectNavigationController;
}
n .m 文件
objViewController =[[HomeViewController alloc]initWithNibName:@"ViewController" bundle:nil];
objectNavigationController = [[UINavigationController alloc]initWithRootViewController:objViewController];
self.window.rootViewController=objectNavigationController;
只需为按钮操作提供与此类似的代码,它就会导航到下一个视图控制器
-(IBAction)buttonClick:(id)sender
{
secondViewController *newObj = [[secondViewController alloc]initWithNibName:@"secondViewController" bundle:nil];
[self.navigationController pushViewController:newObj animated:YES];
}
n 至于导航到上一页的按钮,导航控制器提供了一个按钮,其作用类似于后退按钮。
如果你真的想用一个按钮弹出
-(IBAction)popBack:(id)sender
{
[self.navigationController popViewControllerAnimated:YES];
}
这会做:)
希望这可以帮助。