我正在使用此代码跟踪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 ......