I have a tableView. If I click on a cell, it starts loading the file with the UIActivityIndicator animation. After the download is complete, a check mark appears (the file exists) and the user can proceed to the next controller. It is necessary that after the transition and return back all the checkboxes are gone. How to do it?

 - (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; } } } } 
  • For example, to make the condition under which a tick will be put is not executed and reload the table. - VAndrJ

1 answer 1

The following code in cellForRowAtIndexPath only puts a checkmark , but it will not clear accessoryType if the checkmark and it is not needed (this could be if the table cell was used before):

 BOOL shouldSetCheckmark = ...; // ваша логика решающая должен ли `checkmark` быть показан if (shouldSetCheckmark) { cell.accessoryView = nil; cell.accessoryType = UITableViewCellAccessoryCheckmark; } 

This code will remove the checkmark if it is not needed:

 if (shouldSetCheckmark) cell.accessoryType = UITableViewCellAccessoryCheckmark; else cell.accessoryType = UITableViewCellAccessoryNone; 
  • Your code removes the checkmark if the file does not exist. And I need to put a checkmark after the file is downloaded and remove the checkmark forever if the user has moved to the next controller. - user
  • @user corrected the answer - shouldSetCheckmark should be set accordingly - Dan
  • The whole problem is in logic. A check mark appears when the file is found. That is, I can not hide it if the file still exists. Is it possible to put a tick when the download is complete, and not when the file exists? How do I know when the download was completed without checking the file in the directory? - user
  • @user answered your question about uploading a file here: ru.stackoverflow.com/questions/599924/… - Dan