我有杂志应用程序。其中UITableView
包含自定义单元格。每个单元格中都有按钮、图标、标题和隐藏UIProgressView
。当有人点击按钮时,页面(图像)开始下载。下载某些页面时,我想显示隐藏UIProgressView
或更新。这就是问题所在。我正在使用NSNotification
和performSelectorOnMainThread
更新UIProgressView
. 但是UIProgressView
没有显示。我不知道错误在哪里......谢谢回复!
有一些代码......创建UIProgressView
:
self.progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
[self.progressView setFrame:CGRectMake(250, 200, 92, 28)];
[self.progressView setProgress:0.0];
[self.progressView setHidden:YES];
[self.cellView addSubview:self.progressView];
发布通知:
[[NSNotificationCenter defaultCenter] postNotificationName:kDownloadedIcon object:nil userInfo:dict];
接受通知:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(iconDownloaded:) name:kDownloadedIcon object:nil];
向主线程重新发送通知:
- (void)iconDownloaded:(NSNotification *)notification {
[self performSelectorOnMainThread:@selector(updateProgressBar:) withObject:notification waitUntilDone:YES];}
更新或显示UIProgressView
:
- (void)updateProgressBar:(NSNotification *)notification {
NSDictionary *dict = [notification userInfo];
NSLog(@"%@ %@ %@", [dict objectForKey:@"name"], self.identifier, self.progressView);
if ([[dict objectForKey:@"name"] isEqualToString:self.identifier]) {
if (self.spinner) [spinner stopAnimating];
self.spinner = nil;
[self.spinner removeFromSuperview];
[self.progressView setHidden:NO];
self.progress++;
NSInteger count = [[dict objectForKey:@"pages"] intValue];
[self.progressView setProgress:self.progress/count];
}