我正在尝试在从服务器加载数据时更新 UIProgressview。我有一个带有 sharedInstance 的类来处理服务器通信,并且有一个从服务器获取数据的方法(在 while 循环中)。现在我想通过从我的服务器通信类(sharedInstance)发送通知来更新我的 UIProgressView,但它根本不起作用。
UIProgressView 在 InterfaceBuilder 中正确设置并且 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]];
}
有任何想法吗?