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

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

2016-02-25 17:00 411 查看
@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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: