一.UINavigationController
 
    //  创建一个导航控制器
    // 创建一个控制器作为根控制器 去管理
    RootViewController *rootVC = [[RootViewController alloc]init];
    UINavigationController *navC = [[UINavigationController alloc]initWithRootViewController:rootVC];
    [rootVC release];
    // 把导航控制器作为window的根控制器
    self.window.rootViewController = navC;
    [navC release];
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor greenColor];
   
    // 创建一个按钮 进入下一个页面
    UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];
    button.frame = CGRectMake(100, 100, 100, 100);
    [self.view addSubview:button];
    button.backgroundColor = [UIColor redColor];
    [button setTitle:@"2" forState:(UIControlStateNormal)];
    [button release];
    // 添加方法 进入下一个界面
    [button addTarget:self action:@selector(actionButton:) forControlEvents:(UIControlEventTouchDragInside)];
// 实现Button的方法  进入下一个界面

- (void)actionButton:(UIButton *)button
{
    // 创建下一个界面的
    SecondViewController *secondVC = [[SecondViewController alloc]init];
    // ViewControllers 是导航控制器管理的那一组控制器 所有被管理的控制器们都存放在这个数组中
   // NSLog(@"%@", self.navigationController.viewControllers);
    // 跳转去下一个页面  push
    [self.navigationController pushViewController:secondVC animated:YES];
    [secondVC release];
   // NSLog(@"%@", self.navigationController.viewControllers);
    // 栈顶的控制器
    // 正显示的控制器
    NSLog(@"栈顶%@", self.navigationController.topViewController);

}
 // 返回上一个界面
    [self.navigationController popViewControllerAnimated:YES];
   
   
}
- (void)actionSecondButton:(UIButton *)button
{
   
   
    // 返回根界面
    [self.navigationController popToRootViewControllerAnimated:YES];
   
   
}
- (void)actionThirdButton:(UIButton *)button
{
    // 返回到指定界面
    // 需要从被管理的数组中 把要返回的取出来
    NSArray *viewControllers = self.navigationController.viewControllers;
    SecondViewController *sec = viewControllers[1];
    [self.navigationController popToViewController:sec animated:YES];
    // 或者下面的
    //[self.navigationController popToViewController:self.navigationController.viewControllers[1] animated:YES];

     状态栏高  20
     bar  高  44
    
     */
    self.view.backgroundColor = [UIColor redColor];
    self.navigationItem.title = @"首页";
    // 创建一个UIView出来给titleView   有了View 想往上面加什么都随意
    //UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 44)];
   // view.backgroundColor = [UIColor whiteColor];
    //self.navigationItem.titleView = view;
   
    // 用系统样式初始化一个UIBarButtonItem
    UIBarButtonItem *leftButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(actionLeftBarButtonItem:)];
    self.navigationItem.leftBarButtonItem = leftButton;
    [leftButton release];
   
    // 用标题的初始化方法 初始化右面的按钮
    UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc]initWithTitle:@"确 定" style:(UIBarButtonItemStylePlain) target:self action:@selector(actionRightBarButtonItem:)];
    self.navigationItem.rightBarButtonItem = rightBarButton;
   
    // 用图片初始化UIBarButtonItem
   
    UIBarButtonItem *imageBarButton = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"left"] style:(UIBarButtonItemStylePlain) target:self action:@selector(actionImageBarButton:)];
   
    self.navigationItem.rightBarButtonItem = imageBarButton;
    [imageBarButton release];
   
    // 设置一下Bar 的颜色及图片
   
  //  [self.navigationController.navigationBar setBarTintColor:[UIColor grayColor]];
    // 高44 的把 导航条遮住了,漏出了状态栏
    // 高64 的把 导航栏和状态栏都充满
  //  [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"32064"] forBarMetrics:(UIBarMetricsDefault)];
   
    // 重要的属性
    // 从7.0 以后 导航条默认是半透明的  如果半透明 从屏幕左上角开始计算frame
    // 如果设置成不透明的 从导航条的底部开始计算frame
    // 透明度的设置
    self.navigationController.navigationBar.translucent = NO;
    //
   
   
   
    // Do any additional setup after loading the view.
}
- (void)actionLeftBarButtonItem:(UIBarButtonItem *)barButtonItem
{
    NSLog(@"启动照相机");
}
- (void)actionRightBarButtonItem:(UIBarButtonItem *)barButtonItem
{
    NSLog(@"我是右面的ooo");
}
- (void)actionImageBarButton:(UIBarButtonItem *)barButtonItem
{
    NSLog(@"图片的按钮 ");
二.界面传值
属性传值
     *  从前往后(根 到 顶) 是用属性传值
     1. 点击跳转方法的时候传值
     2. 要传递的是什么? 传递的是数据不是控件
     */
} // 要拿到要传递的数据
    UITextField *textField = (UITextField *)[self.view viewWithTag:888];
    NSString *string = textField.text;
    // 要有一个属性来接收这个数据
    SecondViewController *second = [[SecondViewController alloc]init];
    second.string = string;
代理传值
 *  从后往前(顶 到 根)用代理传值
 1. 协议从哪儿写?   后面的界面写
@protocol SecondDelegate <NSObject>

- (void)changeTextFieldString:(NSString *)string;
@end
@interface SecondViewController : UIViewController
@property (nonatomic,retain)NSString *string;

@end
 2. 协议中要有的方法 传值用  方法中的参数就是咱们要传得值
 3. 顶搞一个代理的属性出来 设置代理 来使用
@property (nonatomic,retain)id<SecondDelegate> delegate;
 4. 根遵守协议 然后 根设置代理 根实现方法
@interface RootViewController : UIViewController<SecondDelegate>
- (void)changeTextFieldString:(NSString *)string
{
    SecondViewController *second = [[SecondViewController alloc]init];
    // 设置代理
   
    UITextField *textField = (UITextField *)[self.view viewWithTag:888];
    textField.text = string;
}
- (void)actionButton:(UIButton *)button
{
   
    // 要拿到要传递的数据
    UITextField *textField = (UITextField *)[self.view viewWithTag:888];
    NSString *string = textField.text;
    // 要有一个属性来接收这个数据
    SecondViewController *second = [[SecondViewController alloc]init];
    second.string = string;
    // 设置代理
    second.delegate = self;
   
    [self.navigationController pushViewController:second animated:YES];
}
 5. 回到后一个界面 顶让代理调用方法进行传值
- (void)actionButton:(UIButton *)button
{
    UITextField *textField = (UITextField *)[self.view viewWithTag:999];
  
    [_delegate changeTextFieldString:textField.text];
   
   
    [self.navigationController popToRootViewControllerAnimated:YES];
}
 6. 根拿到传过来的参数进行赋值
 */
三. NSTIMER
//NSTimer
    // 创建一个定时器  定时循环执行某一个方法  (NSTimeInterval) 时间的间隔  如下 1.0 就是每1.0秒执行一次方法  userInfo  可以当成一个参数  也可以标识这个定时器是干什么的
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timer:) userInfo:@"haha" repeats:YES];
    
    // 激活定时器  相当于启动
    [timer fire];    
    // 停止
    [timer invalidate];
四.NSUserDefaults
// NSUserDefaults  最轻量级的持久化
   
    // 一般只用这个来存储  例如: 账号/密码/设备ID... ...
    // 单例, 目前就叫初始化一个对象就行
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    // 保存
    [userDefaults setObject:@"尚亚雷" forKey:@"shang"];
    // 同步数据
    [userDefaults synchronize];
   
    // 打印沙盒路径
    NSLog(@"%@", NSHomeDirectory());
    /*
     /Users/lanou3g/Library/Developer/CoreSimulator/Devices/F4C0035C-BFC9-4B9A-95D1-59CE94B63E35/data/Containers/Data/Application/1F290708-5666-45D8-9222-AFAD1EC03E16
     */
   
    /*
     // 取出沙盒里面保存的数据
     NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
     NSString *string = [userDefaults objectForKey:@"shang"];
     NSLog(@"%@", string);
     */
// 取出沙盒里面保存的数据
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *string = [userDefaults objectForKey:@"shang"];
    NSLog(@"%@", string);

UI一揽子计划 8 (UINavigationController 、界面通信 、NSTimer  、NSUserDefaults)相关推荐

  1. UI一揽子计划 17 (image的异步加载、KVO观察者模式、KVO进行豆瓣列表界面图片的异步加载)

    把下载图片的封装起来    ImageDownloader.h #import <Foundation/Foundation.h> @protocol ImageDownloaderDel ...

  2. UI一揽子计划 20 (豆瓣实战之图片缓存 、豆瓣实战之详情界面(自适应行高) 、豆瓣实战之登陆注销、刘新林分享之UIAlertController)

    一.图片缓存 ActivityModel.m 如果数据加载完毕就将图片放到缓存中. #pragma mark -- imageDownLoader 代理方法 //  成功返回data - (void) ...

  3. UI一揽子计划 1 (UIView UILabel)

    第一天 1.UIView ·建立一个空模板后,首先将ARC模式关闭,因为iOS采用MRC模式,即手动管理内存. ·重写dealloc方法. - (void)dealloc { [_window rel ...

  4. UI一揽子计划 24 (MVC、通知、)

    一.MVC  Model - View - Controller 即  模型 - 视图 - 控制器 Modle (模型) 存储 处理数据 为应用程序提供数据. View (视图)展示用户界面视图,提供 ...

  5. UI一揽子计划 12 (模态ViewController、单例、通讯录实战、)

    一.模态ViewController 程序中切换⻚面,可以使⽤用UINavigationController.通过导航功能实现⻚面切 换. 某种情况下,可以使⽤视图控制器的一对⽅法实现切换⻚面 1.p ...

  6. UI一揽子计划 22 (多线程概述、NSThread、NSOperationQueue 、GCD、多线程管理)

    一.多进程概述:     进程: 一个正在运行的程序 叫做一个进程     多进程: 多个程序正在运行 叫做多线程     线程: 一个进程 都会有一个或多个线程 如果只有一个 叫做主线程  主线程负 ...

  7. UI一揽子计划 11 (自定义UITableViewCell、Cell 的自适应高度)

    一. 自定义UITableViewCell 在日常的编程中,系统提供的几种Cell 样式 往往不能满足我们的需求.所以需要我们给它进行自定义样式. 自定义Cell 就是创建一个UITableViewC ...

  8. UI一揽子计划 6 (UIControl、UISegmentedControl、UIImageView插入数组图片、UISlider)

    一 UIControl 是所有控制类控件的基类. ·  比如UIButton    UISlider     UISegmentedControl   等只要跟控件有关系的都继承于UIControl类 ...

  9. UI一揽子计划 10 (UITableView 中cell 的编辑, 增加, 删除、UITableViewController 、)

    一.tableView的编辑 tableView 编辑的步骤:    *  1. 让tableView成为可编辑状态       编辑按钮触发方法    *  -1. 激活编辑状态 - (void)r ...

最新文章

  1. 【ruby项目,语言提交检查(一)】怎样高速学习ruby ?
  2. 分布式缓存技术memcached学习(一)——linux环境下编译memcahed
  3. macbook下载苹果版Photoshop cc2019 for mac
  4. 多线程:interrupted、isinterrupted区别
  5. sql is null优化_你不会还在用这8个错误的SQL写法吧?
  6. TCP/IP TIME_WAIT状态原理
  7. [html] 通过设置表单的target=“_blank“来下载文件会被浏览器拦截吗?如何解决?
  8. php 异常错误信息用处,关于PHP中异常错误的处理详细介绍
  9. android 参数 attrs.xml,使用attrs.xml自定义属性
  10. 年薪35W+ 的程序员看过来!百万架构师第3期招生
  11. Ubuntu 挂载新磁盘
  12. iptables oracle策略,利用iptables防火墙保护Oracle数据库
  13. jpush推送格式 swift_Swift - JPush极光推送的使用6(定时推送通知)
  14. add script param in pycharm
  15. open cv+C++错误及经验总结(五)
  16. phpstorm内网远程debug
  17. 最新中国大陆行政区域划分
  18. VC的一些实用技巧和注意事项。
  19. 计算机右键管理提示没有关联应用,win10系统计算机右键管理提示没有与之关联的程序的解决方法...
  20. CPAN | 配置阿里源

热门文章

  1. dw给HTML加背景音乐,Dreamweaver怎样为网页添加背景音乐播放器?
  2. 拿下Offer:数据分析师求职面试指南
  3. Vue开发实例(16)之创建标签页
  4. 使用el-menu打开新标签页到外部网址
  5. 开发者,为什么需要构建知识图谱
  6. windows 不能在本地计算机启动apache2。有关更多信息,查阅系统事件日志。如果这是非Microsoft服务,...
  7. 2022车工(技师)考试题库模拟考试平台操作
  8. bootstrap table 怎么自适应宽度
  9. objectarx 读取外部DWG图到当前图形
  10. 一千万数据,怎么快速查询?