IOS学习 NSNavigationController1 父子页面跳转 导航栏隐藏

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // Override point for customization after application launch.

    

    self.homeVC = [[HomeViewController alloc]init];

    UINavigationController *navigation = [[UINavigationController alloc]initWithRootViewController:self.homeVC];

    self.window.rootViewController = navigation;

    

    return YES;

}




#import "HomeViewController.h"


@interface HomeViewController ()


@end


@implementation HomeViewController


- (void)loadView{

    UIView *baseView = [[UIView alloc]initWithFrame:[[UIScreen mainScreen]applicationFrame]];

    self.view = baseView;

    baseView.backgroundColor = [UIColor purpleColor];


}


- (void)viewDidLoad {

    [super viewDidLoad];

    

    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(100, 100, 200, 40)];

    button.layer.cornerRadius = 8;

    button.backgroundColor = [UIColor greenColor];

    [button setTitle:@"push" forState:UIControlStateNormal];

    [button addTarget:self action:@selector(pushTV) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:button];  

}


-(void)pushTV{

    UIViewController *SecondTV = [[SecondViewController alloc]init];

    //跳转至子页面

    [self.navigationController pushViewController:SecondTV animated:YES];

}


- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

}


@end





#import "SecondViewController.h"


@interface SecondViewController ()


@end


@implementation SecondViewController


- (void)viewDidLoad {

    [super viewDidLoad];

    // Do any additional setup after loading the view.

    UIButton *button = [[UIButton alloc]initWithFrame:CGRectMake(100, 100, 200, 40)];

    button.layer.cornerRadius = 8;

    button.backgroundColor = [UIColor purpleColor];

    [button setTitle:@"second" forState:UIControlStateNormal];

    [button addTarget:self action:@selector(backTV) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:button];

    

    UIButton *saveBtn = [[UIButton alloc]initWithFrame:CGRectMake(125, 200, 150, 40)];

    saveBtn.layer.cornerRadius = 8;

    saveBtn.backgroundColor = [UIColor orangeColor];

    [saveBtn setTitle:@"保存" forState:UIControlStateNormal];

    [saveBtn addTarget:self action:@selector(saveClick) forControlEvents:UIControlEventTouchUpInside];

    [self.view addSubview:saveBtn];

    

}


-(void)backTV{

    //导航栏隐藏

    if (self.navigationController.toolbarHidden) {

        [self.navigationController setToolbarHidden:NO animated:YES];

        [self.navigationController setNavigationBarHidden:NO animated:YES];

    }else

    {

        [self.navigationController setToolbarHidden:YES animated:YES];

        [self.navigationController setNavigationBarHidden:YES animated:YES];

    }


}


-(void)saveClick{

    //返回主页面

    [self.navigationController popToRootViewControllerAnimated:YES];


}

- (void)didReceiveMemoryWarning {

    [super didReceiveMemoryWarning];

}


@end




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值