CustomCell中的UIProgressView在发送NSNotification时从不显示

时间:2012-09-10 14:39:40

标签: ios multithreading uitableview nsnotifications uiprogressview

我有杂志应用程序。 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];
}

1 个答案:

答案 0 :(得分:1)

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