官术网_书友最值得收藏!

NSProgress

iOS 7 introduces a completely new class to the Foundation framework, NSProgress. Using NSProgress involves treating each task of an action as a milestone of completion. By doing so, you, the developer, can track progress directly in code and perform individual tasks for each milestone.

For instance, to perform a particular action, you may require four separate tasks to be completed. Each task is capable of monitoring its own progress, and will report once the task is complete. In our example, this would increase the percent of completion to 25.

NSProgress uses Key Value Observing (KVO) to provide notifications related to progress. These notifications can be used to update a UI component displaying progress to the user, such as a progress bar or label. The following code is a very simple implementation that demonstrates working with NSProgress to report progress in a localized manner:

NSArray *data = @[@"Data 1", @"Data 2", @"Data 3", @"Data 4"];

  self.dataProgress = [NSProgress progressWithTotalUnitCount:data.count];

  int index = 0;

  for (NSString *string in data) {

  // Do something with string or other data
    index ++;
    self.dataProgress.completedUnitCount = index;


    NSLog(@"%@", [self.dataProgress localizedDescription]);

  }
主站蜘蛛池模板: 东安县| 屯门区| 安泽县| 盈江县| 潞西市| 玉环县| 临清市| 静海县| 高州市| 乌海市| 化州市| 定日县| 卢湾区| 江门市| 大同县| 固镇县| 米泉市| 南城县| 灌阳县| 黄陵县| 城市| 七台河市| 兴义市| 手游| 隆尧县| 西丰县| 客服| 金平| 迁西县| 福泉市| 金坛市| 界首市| 阳高县| 察雅县| 河源市| 乐业县| 辉南县| 开江县| 柳州市| 临西县| 广东省|