2016-11-15 1 views
-1

以下のようなすべてのテーブルビューセルに循環カスタム進行状況ビューを追加します。すべてのテーブルビューセルから進行状況ビューを削除します

cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
if (cell == nil) { 
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
} 

// progressView = (M13ProgressViewPie *)[cell viewWithTag:100]; 

progressView = [[M13ProgressViewPie alloc] initWithFrame:CGRectMake(0.0, 0.0, 50.0, 5.0)]; 
progressView.tag = indexPath.row; 

NSLog(@"%ld",(long)progressView.tag); 
// Configure the progress view here. 
[progressView setAnimationDuration:10.0]; 

// Add it to the view. 
[cell.contentView addSubview: progressView]; 

// Update the progress as needed 
[progressView setProgress: 1.0 animated: YES]; 

私は10秒

[NSTimer scheduledTimerWithTimeInterval:10.0 target:self selector:@selector(updateUI) userInfo:nil repeats:YES]; 

のnstimer後、円形の進捗状況をリロードしたいとのupdateUI方法で私は、セルのコンテンツビューのサブビューを削除しています。

これで、最後のセルの進行状況を再読み込みすることしかできませんでした。それはすべての細胞に適用されていません。 viewDidLoad


- (void)updateUI { 
    isProgressRemove = yes; 
    [self.tableView reload]; 
    isProgressRemove = NO; 
} 
+0

いくつかのコードを共有します。更新UIメソッドの – KKRocks

+0

:NSArray * subviews = [cell.contentView subviews]; (サブビューのM13ProgressView *サブビュー){ [subview removeFromSuperview]; } –

+0

ここで、開始タイマーは何ですか?中に追加? – KKRocks

答えて

0
CellForRowAtIndextPath


if(isProgressRemove) { 
    NSArray* subviews = [cell.contentView subviews]; 
    for (UIView *view in subviews) { 
     if((view isKindOfClass:[M13ProgressView class])) { 
      [subview removeFromSuperview]; 
     } 
    } 
} 

あなたのコードでは、大きな問題があります。同じセルに多くの進行状況ビューを追加します。テーブルビューは変更を加えずにセルを再利用するために発生しました。
セルが再利用されている場合は、2番目の進行状況ビューが追加されます。このメソッドにチェックインすると、セルに進行状況が表示されますか?たとえば、次のコードを使用することができます。

<...> 
UIView* currentProgressView = [cell.contentView viewWithTag:100]; 
if (currentProgressView) 
{ 
    //remove or update progress value 
} 
else 
{ 
    //create if needed 
} 
<...> 
0

関連する問題