Ios 从所有表视图单元格中删除进度视图
我将向所有表格视图单元格添加一个循环自定义进度视图,如下所示Ios 从所有表视图单元格中删除进度视图,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我将向所有表格视图单元格添加一个循环自定义进度视图,如下所示 cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; } // progressView =
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];
在updateUI方法中,我将删除单元格内容视图子视图
有了这个,我只能重新加载最后一个单元格进度视图。它不适用于所有单元格。在CellForRowAtIndextPath中
在ViewDidLoad中
你的代码有大问题。可以向同一单元格添加多个进度视图。之所以发生这种情况,是因为表视图无需修改即可重用单元格。
如果单元格被重用,您将向其添加第二个进度视图。您应该检查此方法单元格是否包含进度视图。例如,您可以使用以下代码:
<...>
UIView* currentProgressView = [cell.contentView viewWithTag:100];
if (currentProgressView)
{
//remove or update progress value
}
else
{
//create if needed
}
<...>
UIView*currentProgressView=[cell.contentView视图带标记:100];
如果(currentProgressView)
{
//删除或更新进度值
}
其他的
{
//如果需要,创建
}
共享一些代码。在更新UI方法中:NSArray*子视图=[cell.contentView子视图];对于(M13ProgressView*子视图中的子视图){[subview removeFromSuperview];}启动计时器在哪里?在添加时在中?我在视图中添加它loadok以及如何在updateUI函数中获取单元格?
- (void)updateUI {
isProgressRemove = yes;
[self.tableView reload];
isProgressRemove = NO;
}
<...>
UIView* currentProgressView = [cell.contentView viewWithTag:100];
if (currentProgressView)
{
//remove or update progress value
}
else
{
//create if needed
}
<...>