title: Activity indicator view in table cell
body: <p>I have a table, I want to make it so that when I click on a cell, the activity indicator spins around it, and not somewhere in an incomprehensible place</p>
  
  <p><a href="https://i.stack.imgur.com/2YHBZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2YHBZ.png" alt="enter image description here"></a></p>
  
  <p>It looks like this. In the code, I have the MainViewController module and the Presenter module which determines when to start the activity indicator. I have an outlet</p>
  
  <pre><code>@IBOutlet weak var activity: UIActivityIndicatorView! = UIActivityIndicatorView(style: .gray)
  </code></pre>
  
  <p>I have two functions in the view controller that start the animation and stop</p>
  
  <pre><code>func startActivity() {
     activity.startAnimating()
  }
  
  
  func stopActivity() {
     activity.stopAnimating()
  }
  </code></pre>
  
  <p>there is a function that handles a click on a cell</p>
  
  <pre><code>func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
     tableView.deselectRow(at: indexPath, animated: true)
     output.callFromThePresenter(array: array[indexPath.row])
  
  }
  </code></pre>
  
  <p>This function is implemented in the presenter.</p>
  
  <pre><code>func callFromThePresenter(array: String) {
  
    let userInteractiveQueue = DispatchQueue.global(qos: .userInteractive)
  
    async {
      DispatchQueue.main.async  {
          self.view.startActivity()
      }
      userInteractiveQueue.async {
           self.interactor.functionFromInteractor(data: array)
      }
    }
  }
  </code></pre>
  
  <p>as I assumed, in the view controller, when you click on a cell, the callFromThePresenter () function will work, and the animation function and the data transfer function in the Interactor will start in it, as soon as the Interactor has completed this function, it will return the data to the Presenter and inside the call back function, I will run the stopActivity () function. And it worked until I decided to set the positioning</p>
  
  <pre><code>func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
     tableView.deselectRow(at: indexPath, animated: true)
     output.callFromThePresenter(array: array[indexPath.row])
     let cell = tableView.cellForRow(at: indexPath)
     cell?.accessoryView = self.activity
  }
  </code></pre>
  
  <p>as soon as i added these two lines</p>
  
  <pre><code>let cell = tableView.cellForRow(at: indexPath)
  cell?.accessoryView = self.activity
  </code></pre>
  
  <p>I broke everything, as if I started up, I click on the table cell and the wheel turns where it is needed and everything works, but after receiving the result, I poke at some cell again, the whole program hangs, and I don’t know for what reason . At the same time, the functions work out how much I can understand it, because it comes to the console that the function was launched and got some result, but then the whole UI hangs tight and I can't do anything</p>