您的位置:首页 > 移动开发 > IOS开发

IOS学习之——navigationController的界面跳转方法

2016-04-15 13:23 337 查看
在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];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: