2

我有杂志应用程序。其中UITableView包含自定义单元格。每个单元格中都有按钮、图标、标题和隐藏UIProgressView。当有人点击按钮时,页面(图像)开始下载。下载某些页面时,我想显示隐藏UIProgressView或更新。这就是问题所在。我正在使用NSNotificationperformSelectorOnMainThread更新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];
}
4

1 回答 1

1

欢呼!感谢蒂姆的想法!您的“简单项目”帮助我解决了它。问题是,我开始循环。在这个循环中,我发布通知。但是当 for 开始时,它会阻塞主线程并且 UI 没有被重绘。所以我将 for 循环的调用发送到后台,一切正常。再次感谢蒂姆

于 2012-09-12T14:49:38.337 回答