gpt4 book ai didi

ios - NSObject 类标签的连续更新值

转载 作者:行者123 更新时间:2023-11-28 21:35:45 25 4
gpt4 key购买 nike

我的歌曲正在从辅助类(派生自 NSObject)播放,我想更新 View 中的 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;
}
}];
}

最佳答案

如果您从 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;
}
}]

关于ios - NSObject 类标签的连续更新值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33998779/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com