zoukankan      html  css  js  c++  java
  • KVO KVC

    @interface FoodData : NSObject

    {

        NSString * foodName;

        float foodPrice;    

    }

    @end

     

    ////////////////////////////////////////////////////////////////////////////

        

    foodData = [[FoodDataalloc]init];

        [foodDataaddObserver:selfforKeyPath:@"foodName"options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOldcontext:nil];

        [foodDataaddObserver:selfforKeyPath:@"foodPrice"options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOldcontext:nil];

     

        ///调用

        [foodDatasetValue:@"apple"forKey:@"foodName"];

        [foodDatasetValue:@"100.0"forKey:@"foodPrice"];

     

    ///////响应

    -(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context

    {

        if( [keyPath isEqualToString:@"foodName"])

        {

            NSLog(@"foodName:%@",[foodDatavalueForKey:@"foodName"]);

        }

        else if( [keyPath isEqualToString:@"foodPrice"])

        {

             NSLog(@"foodPrice:%@",[foodDatavalueForKey:@"foodPrice"]);

        }

    }

  • 相关阅读:
    函数的定义
    编码转换
    bytes类型
    用py操作文件(file类的功能)
    HASH哈希
    二进制、bit、 bytes
    POJ3225
    POJ1436
    HDU1394
    HDU1272
  • 原文地址:https://www.cnblogs.com/rollrock/p/3737747.html
Copyright © 2011-2022 走看看