iOS NSProgress的使用

 

@interface ZXViewController ()

 

@property (nonatomic, strong) NSProgress *pro;

- (IBAction)btnOnClick:(id)sender;

 

 

@end

 

@implementation ZXViewController

 

- (void)viewDidLoad

{

    [super viewDidLoad];

 

    NSProgress *pro = [NSProgress progressWithTotalUnitCount:10000.0];

    

    // 注册一个监听器  KVO

    [pro addObserver:self forKeyPath:@"fractionCompleted" options:NSKeyValueObservingOptionNew context:nil];

   

}

 

- (IBAction)btnOnClick:(id)sender {

    // 模拟改变他的属性

    self.pro.completedUnitCount += 100;

}

 

// 监听到了属性改变会调用这个方法

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

{

    NSLog(@"lskdjfl=  %f",self.pro.fractionCompleted);

}

 

@end

posted @ 2014-09-25 16:29  追求无止尽  阅读(8560)  评论(0编辑  收藏  举报