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

来源:互联网 发布:linux grep 命令 编辑:程序博客网 时间:2024/06/01 08:24

在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];    }








0 0