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

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]);

  }
主站蜘蛛池模板: 宜君县| 芜湖市| 郴州市| 浦江县| 息烽县| 岳普湖县| 南溪县| 黎平县| 涿州市| 灌南县| 乡城县| 高台县| 万安县| 东安县| 九龙坡区| 高清| 肃北| 海伦市| 象山县| 绍兴市| 镇沅| 泽库县| 永仁县| 汝州市| 丹阳市| 辽宁省| 吉木萨尔县| 司法| 固阳县| 察雅县| 天柱县| 安图县| 承德市| 淄博市| 宁晋县| 宜昌市| 汉沽区| 台山市| 车险| 芦溪县| 湟中县|