我試圖從服務器加載數據時更新UIProgressview。我有一個具有sharedInstance的類來處理服務器通信,並且有一種從服務器獲取數據的方法(在while循環中)。現在我想通過從我的server-communication-Class(sharedInstance)發送通知來更新我的UIProgressView,並且它根本不起作用。更新帶有通知的UIProgressView
在InterfaceBuilder中正確設置了UIProgressView並且show/hide/setProgress工作正常,但setProgress無法通過通知工作。
下面是測試循環在我的服務器通信類:
- (void)completeServerQueue {
NSNumber *progress = [[NSNumber alloc] init];
for (int i=0; i<15; i++) {
progress = [[NSNumber alloc] initWithFloat:(100/15*i) ];
float test = [progress floatValue];
[[NSNotificationCenter defaultCenter]
postNotificationName:@"ServerQueueProgress"
object:progress];
sleep(1);
}
}
而且這是在檢測到通知時調用的方法(我用的斷點檢查了它,它是執行...):
- (void)serverQueueProgress:(NSNotification *)notification {
[serverQueueProgressView setProgress:[[notification object] floatValue]];
}
任何想法?