【发布时间】:2016-12-04 08:48:55
【问题描述】:
我有一个表格视图。如果我单击单元格,它将开始下载带有UIActivityIndicator 动画的文件。下载完成后出现复选标记(文件存在),用户可以移动到下一个控制器。必要的是,在移动到下一个控制器并返回后,所有复选标记都消失了。怎么做?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: [NSString stringWithFormat:@"Cell%d", indexPath.row] forIndexPath:indexPath];
if (indexPath.row == 1){
if (!fileExists) {
[_spinner startAnimating];
}
if (fileExists) {
cell.accessoryView = nil;
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
if (indexPath.row == 2){
if (!fileExists1) {
[_spinner1 startAnimating];
}
if (fileExists1) {
cell.accessoryView = nil;
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 1) {
if (!fileExists) {
_spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
_spinner.frame = CGRectMake(0, 0, 24, 24);
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.accessoryView = _spinner;
tableView cellForRowAtIndexPath:indexPath].accessoryView = _spinner;
[_spinner startAnimating];
if (fileExists) {
[tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
}
}
}
}
【问题讨论】:
-
您能否添加更多代码,例如
cellForRowAtindexPath和didSelectRowAtIndexPath。 -
@user 检查答案,这是您的要求吗?
-
@NiravD 我更新了我的问题。请检查。
-
在不更新 model(数据源数组)的情况下,基本上不要操作 view(单元格)。下次重新加载表视图时,只考虑模型中的当前状态。
标签: ios objective-c cell