2

我有雜誌應用程序。有UITableView其中包含自定義單元格。在每個單元格中都是按鈕,圖標,標題和隱藏UIProgressView。當有人點擊按鈕時,頁面(圖像)開始下載。當某個頁面被下載時,我想要顯示隱藏的UIProgressView或更新。還有問題。我正在使用NSNotificationperformSelectorOnMainThread來更新UIProgressView。但UIProgressView不顯示。我不知道錯誤在哪裏...... Thx回覆!當NSNotification發送時,CustomCell中的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]; 

發帖notificaiton:

[[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]; 
} 
+0

你的'NSLog'裏面有'-updateProgressBar:'顯示在控制檯中嗎? – Tim

+0

是的,控制檯寫得很好。 –

+0

你可以在調用'[self.progressView setHidden:NO]'之前設置一個斷點嗎?檢查看看'self.progressView'是什麼(確保它不是'nil'),查看它的框架,它的超級視圖等。 – Tim

回答

1

萬歲!蒂姆蒂姆的想法!你的「簡單項目」幫助我解決了這個問題。問題是,我開始循環。在這個循環中,我發佈了通知。但是當啓動時,它會阻止主線程,並且UI未被重繪。所以我發出呼籲循環到背景,一切正常。 Thx再添Tim

相關問題