推送
//推出 控制器视图
[self.navigationController pushViewController:findPwdVC animated:YES];
返回
//返回到 根视图控制器
[self.navigationController popToRootViewControllerAnimated:YES];
//返回到 指定控制器
//这个指定控制器,必须是导航控制器的栈中所在的控制器视图。
[self.navigationController popToViewController:self.navigationController.viewControllers[1] animated:YES];
//返回到上一个视图控制器
[self.navigationController popViewControllerAnimated:YES];
==============================================================
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
LoginViewController *loginVC = [[LoginViewController alloc]init];
//设置导航控制器作为window的根视图控制器
UINavigationController *rootNC = [[UINavigationController alloc]initWithRootViewController:loginVC];
self.window.rootViewController = rootNC;
//半透明-原点(0,0),不透明-原点(0,64)
// rootNC.navigationBar.translucent = YES;
//设置item的渲染颜色
// rootNC.navigationBar.tintColor = [UIColor cyanColor];
//设置导航条的渲染颜色
// rootNC.navigationBar.barTintColor = [UIColor redColor];
//设置导航条隐藏
// rootNC.navigationBarHidden = YES;
// UIBarMetricsCompact 设置横屏下导航条图片
// UIBarMetricsDefault设置竖屏下导航条图片
// [rootNC.navigationBar setBackgroundImage:[UIImage imageNamed:@"bgg.jpg"] forBarMetrics:UIBarMetricsDefault];
//一般图片占好几K,为了节约内存,大多数情况下,会裁剪一些图片,这些图片可以自己拼接。
return YES;
}
==============================================
-(void)loadView
{
self.findPwdView = [[FindPasswordView alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.view = self.findPwdView;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//返回到 根视图控制器
// [self.navigationController popToRootViewControllerAnimated:YES];
//返回到 指定控制器
//这个指定控制器,必须是导航控制器的栈中所在的控制器视图。
// [self.navigationController popToViewController:self.navigationController.viewControllers[1] animated:YES];
//返回到上一个视图控制器
[self.navigationController popViewControllerAnimated:YES];
//获取栈顶的控制器
NSLog(@"%@",self.navigationController.topViewController);
//获取可见的控制器,如果是模态(上下推送的)的话,会是模态的视图,此时,并不是栈顶控制器。--不常用,面试会用到。
NSLog(@"%@",self.navigationController.visibleViewController);
}
=====================================================
-(void)loadView
{
self.loginView = [[LoginView alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.view = self.loginView;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//推出注册页面
//1.创建
RegisteViewController *registerVC = [[RegisteViewController alloc]init];
//2.使用导航控制器 推出 新控制器
[self.navigationController pushViewController:registerVC animated:YES];
//属性传值第二步:给属性赋值
UITextField *textField = (UITextField *)self.navigationItem.titleView;
registerVC.value = textField.text;
}
- (void)viewDidLoad {
[super viewDidLoad];
//设置title
// 每个控制器视图 都有一个navigationItem.
// self.navigationItem
// self.navigationController.navigationItem
self.navigationItem.title = @"登录";
//不是视图,但是还可以见.
// self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(rightBarButtonItem:)];
//可以使用initWithCustomView来自定义(UIView)按钮
UISegmentedControl *segmentedControl = [[UISegmentedControl alloc]initWithItems:@[@"+",@"-"]];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:segmentedControl];
//可以使用titleView 来替换原来的文字标题
UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(-30, -20, 200, 30)];
textField.borderStyle = UITextBorderStyleRoundedRect;
self.navigationItem.titleView = textField;
}
======================================================
-(void)loadView
{
self.registeView = [[RegisteView alloc]initWithFrame:[UIScreen mainScreen].bounds];
self.view = self.registeView;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
FindPwdViewController *findPwdVC = [[FindPwdViewController alloc]init];
//推出 控制器视图
[self.navigationController pushViewController:findPwdVC animated:YES];
}
- (void)viewDidLoad {
[super viewDidLoad];
//属性传值第三步:取值使用
self.navigationItem.title = self.value;
}