zoukankan      html  css  js  c++  java
  • UI进阶之网络进阶KVO

    引入框架

    #import
    "ViewController.h" #import <CommonCrypto/CommonCrypto.h> @interface ViewController () //添加数组属性 @property (nonatomic, strong) NSMutableArray *array; @end @implementation ViewController #warning ---重中之重--- //移除观察者 - (void)dealloc { //只要使用KVO 那就一定要写这个移除观察者的方法 [self removeObserver:self forKeyPath:@"array"]; } - (void)viewDidLoad { [super viewDidLoad]; //谁去观察谁的哪一个属性,检查它变化的时间 //添加一个观察者 //第一个self 表示观察者 //第一个参数: 被观察者 //第二个参数: 哪一个属性被观察 //第三个参数: 什么时候触发观察者方法 //第四个参数: 保险, 可以添加一些字符串 self.array = [NSMutableArray array]; [self addObserver:self forKeyPath:@"array" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context:nil]; } - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { NSArray *array = @[@"1", @"2"]; //[self.array setArray:array]; //KVC的方法 [[self mutableArrayValueForKeyPath:@"array"]setArray:array]; } //观察者模式触发的方法 - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context { NSLog( @"keypath == %@", keyPath); NSLog(@"object == %@", object); NSLog(@"change == %@", change); }
  • 相关阅读:
    web.config中的customErrors标记的用法
    算法系列15天速成[索引]
    log4net的简单使用
    Cookie帮助类
    ASPxTreeList及ASPxGridView使用
    javascript获取页面中的位置
    如何部署windows服务?
    基于T4模板引擎生成静态网站(CMS)
    SqlServer实现递归查询
    安卓(AndRoid)开发环境搭建之HelloWord
  • 原文地址:https://www.cnblogs.com/huyibo/p/5365379.html
Copyright © 2011-2022 走看看