在AppDelegate中
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window=[[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
FiristViewController *vc1=[[FiristViewController alloc]init];
//创建导航控制器
UINavigationController *navi=[[UINavigationController alloc]initWithRootViewController:vc1];
self.window.rootViewController=navi;
[self.window makeKeyAndVisible];
return YES;
}
页面1 中FiristViewController
@implementation FiristViewController
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//创建目标VC
SecondViewController *vc2=[[SecondViewController alloc]init];
//通过导航器控制跳转
//获取当前VC所在的NavigationController
[self.navigationController pushViewController:vc2 animated:YES];
}
- (void)viewDidLoad {
[super viewDidLoad];
//设置颜色,用下view,或使用view后才可以点
self.view.backgroundColor=[UIColor redColor];
self.navigationItem.title=@"今日头条";
// self.navigationItem.
}
页面2中
SecondViewController
@implementation SecondViewController
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
//所有的都通过导航控制器回去。
[self.navigationController popViewControllerAnimated:YES];
[self.navigationController viewControllers];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor=[UIColor greenColor];
}