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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM