来自NSObject类的标签的连续更新值

时间:2015-11-30 12:32:30

标签: ios objective-c

我的歌是从辅助类(从NSObject派生)播放的,我想在视图中更新UI,我知道一种方法PostNotification。还有其他解决方案吗?

+(void)playRemoteFile:(NSString*)songURL {

    [[AFSoundManager sharedManager] startStreamingRemoteAudioFromURL:songURL andBlock:^(int percentage, CGFloat elapsedTime, CGFloat timeRemaining, NSError *error, BOOL finished) {

        if (!error) {
            // I want to update GUI here
            //_slider.value = percentage * 0.01;                
        } 
    }];
}

1 个答案:

答案 0 :(得分:2)

如果从viewController调用playRemoteFile,则可以修改playRemoteFile方法。如何将其更改为:

+ (void)playRemoteFile:(NSString*)songURL andBlock:(void (^)(int percentage, CGFloat elapsedTime, CGFloat timeRemaining, NSError *error, BOOL finished))block {
    [[AFSoundManager sharedManager] startStreamingRemoteAudioFromURL:songURL andBlock:^(int percentage, CGFloat elapsedTime, CGFloat timeRemaining, NSError *error, BOOL finished) {
        block(percentage, elapsedTime, timeRemaining, error, finished)
    }];
}

然后在viewController中执行此操作

[someObject playRemoteFile: songURL andBlock:^(int percentage, CGFloat elapsedTime, CGFloat timeRemaining, NSError *error, BOOL finished){
    if (!error) {
        // update GUI here
        //_slider.value = percentage * 0.01;                
    } 
}]