我使用多重连接在蓝牙上发送文件。进度存储在名为Progress:
的变量中NSProgress* progress;
以这种方式访问它:
progress.fractionCompleted
如果数字发生变化,如何调用方法来更新我的UIprogressBar?
有一种方法:
-(void)session:(MCSession *)session didStartReceivingResourceWithName:(NSString *)resourceName fromPeer:(MCPeerID *)peerID withProgress:(NSProgress *)progress
{
NSLog(@"RECEIVING... %@ from peer: %@", progress, peerID);
}
但它只被召唤一次......
答案 0 :(得分:5)
你可以在fractionCompleted这样的
上使用KVO [_progress addObserver:self
forKeyPath:@"fractionCompleted"
options:NSKeyValueObservingOptionNew
context:NULL];
然后覆盖observeValueForKeyPath
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context
{
if (object == _progress) {
// Handle new fractionCompleted value
return;
}
[super observeValueForKeyPath:keyPath
ofObject:object
change:change
context:context];
}
您可以查看Matt博客了解更多详情 http://www.raywenderlich.com/49850/whats-new-in-objective-c-and-foundation-in-ios-7