あなたが欠けているキーは、NSProgress
クラスが進捗オブジェクトのツリーとして使用されるように設計されていると思います。さらに、このツリーは、親プロセスに暗黙的に作成されます。子プロセスは、親にアタッチされていることを意識する必要はありません。
私はOS X Foundationリリースがはるかに便利NSProgress
のクラス参照よりもノートが見つかりました:
https://developer.apple.com/library/Mac/releasenotes/Foundation/RN-Foundation/index.html
ハンドラがUIコントローラロジックとデータコントローラロジックの両方のために使用することができると思われる理由があります親子階層を構築するときに、両方に使用できるハンドラのセットが2つあることを確認してください。親のハンドラはUIコントローラレベル(進捗の「消費者」)に設定され、子のハンドラはデータコントローラ(「プロバイダ」)によって設定されます。
becomeCurrentWithPendingUnitCount:
を使用して暗黙的に関係を作成できるため、子プログレスオブジェクトは親から隔離されているため、クライアントがデータレベルハンドラを上書きする心配が軽減されます。
進捗オブジェクトのpause
またはcancel
を呼び出すと、その呼び出しをツリーに伝播し、途中でハンドラを呼び出します。
例:
// UI controller level, probably a UIViewController subclass.
- (void)handleDoSomethingButtonTapped:(UIButton *)sender
{
self.progressThatWeObserve =
[NSProgress progressWithTotalUnitCount:100]; // 100 is arbitrary
self.progressThatWeObserve.pausingHandler = ^{
// Update UI, reflect paused state ...
};
[self.progressThatWeObserve becomeCurrentWithPendingUnitCount:100];
[self.dataController doSomethingInBackgroundWithCompletionHandler:^{
// Update UI, remove from view ...
}];
[self.progressThatWeObserve resignCurrent];
}
// Data controller level, a SomethingManager class maybe.
- (void)doSomethingInBackgroundWithCompletionHandler:(void (^)(void)completionHandler
{
self.progressThatWeManipulate =
[NSProgress progressWithTotalUnitCount:289234]; // e.g. bytes to upload
self.progressThatWeManipulate.pausingHandler = ^{
// Actually suspend the network operation ...
};
dispath_async(self.workerQueue, ^{
// Periodically update progress
});
}
私は実際にこののいずれかを行っていないのでご注意ください、それは、ドキュメントを読んでから、すべての理論です。
私はプライベートクラスのようですが、あなたはそれを使いたいですか? – Ian
プライベートではありません。 [Appleの開発者のドキュメント](https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSProgress_Class/Reference/Reference.html) –
私の悪い、私は存在していたことが分かりませんでした。 – Ian