我正在使用此代码来跟踪 NSProgress 中不断变化的数字:
[progress addObserver:self forKeyPath:kProgressCancelledKeyPath options:NSKeyValueObservingOptionNew context:NULL];
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
NSProgress *progress = object;
NSLog(@"PROG: %f", progress.fractionCompleted);
// Check which KVO key change has fired
if ([keyPath isEqualToString:kProgressCancelledKeyPath]) {
// Notify the delegate that the progress was cancelled
}
else if ([keyPath isEqualToString:kProgressCompletedUnitCountKeyPath]) {
// Notify the delegate of our progress change
NSLog(@"PROG: %f", progress.fractionCompleted);
if (progress.completedUnitCount == progress.totalUnitCount) {
// Progress completed, notify delegate
NSLog(@"PROG: %f", progress.fractionCompleted);
}
}
}
这就是我得到的:
<NSProgress: phase=Loading; state=Waiting; fractionCompleted=0.000000> from peer: <MCPeerID: 0x14e1f220 DisplayName = alessandro's iPod touch-593288>
注意更多。我想使用完成分数的进度视图,但我没有得到任何价值。NSlog PROG 永远不会被调用...