雑誌アプリを持っています。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];
}