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
- (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
相关文章推荐
- iOS 复习题
- iOS 复习题
- JSPatch - iOS 动态补丁
- iOS 内存泄漏问题
- vim基本命令
- iOS控件之日历
- [IOS 开发] instancetype和id的区别
- iOS本地搜索(谓词)
- IOS发布的一些坑
- iOS开发--CocoaPods使用
- 详解 iOS navigationBar 的设置问题
- ios autolayout 使用总结
- #import与@class的区别
- [充电][ios]ios充电接口
- ios开发——iOS9 3D Touch 使用教程
- iOS开发之设置导航栏标题的字体大小和颜色
- iOS:手把手教你发布代码到CocoaPods(Trunk方式)
- iOS 创建带有Xib文件ViewController时 如何正确设置frame?
- iOS App集成Apple Pay教程(附示例代码)
- iOS 视频边下边播