我有杂志应用程序。 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];
}
最佳答案
欢呼吧!谢谢蒂姆的想法!你的“简单项目”帮助我解决了它。问题是,我开始循环。在这个循环中,我发布通知。但是当 for 开始时,它会阻塞主线程并且 UI 没有被重绘。所以我将 for 循环调用发送到后台,一切正常。再次感谢提姆
关于ios - 发送 NSNotification 时,CustomCell 中的 UIProgressView 从不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12353984/