【问题标题】:track changes in NSProgress with Multipeer Connectivity使用 Multipeer Connectivity 跟踪 NSProgress 的变化
【发布时间】:2013-10-04 19:31:27
【问题描述】:

我正在使用多点连接在蓝牙上发送文件。进度存储在一个名为 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);

}

但它只被调用一次......

【问题讨论】:

    标签: ios multipeer-connectivity


    【解决方案1】:

    你可以在类似的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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多