title: How to set enabled checkimage in tableview based on the selected cells
body: <p>I am fetching previously selected categorylist from the server. say for an example.cateogrylist i fetched from the server was in following formate </p>
  
  <pre><code>categoryid : 2,6,12,17
  </code></pre>
  
  <p>now what i need to do is want to enable checkmark in my tableview based on this categorylist,for that purpose i converted this list into an [Int] array like this :</p>
  
  <pre><code>func get_numbers(stringtext:String) -&gt; [Int] {
      let StringRecordedArr = stringtext.components(separatedBy: ",")
      return StringRecordedArr.map { Int($0)!}
  }
  </code></pre>
  
  <p>in viewDidLoad() :</p>
  
  <pre><code>  selectedCells = self.get_numbers(stringtext: UpdateMedicalReportDetailsViewController.catId)
    print(myselection)
  </code></pre>
  
  <p>while printing it's giving me results like this : <strong>[12,17,6,8,10]</strong></p>
  
  <p>i want to enable checkimage based on this array.I tried some code while printing its giving me the right result like whatever the categories i selected at the time of posting ,i am able to fetch it but failed to place back this selection in tableview.Requirement : while i open this page it should show me the selection based on the categorylist i fetched from the server.</p>
  
  <pre><code>var selectedCells : [Int] = []
  
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell
  {
      let cell1  = table.dequeueReusableCell(withIdentifier: "mycell") as! catcell
  
      cell1.mytext.text = categoriesName[indexPath.row] 
        if UpdateMedicalReportDetailsViewController.flag == 1
      {
            selectedCells = self.get_numbers(stringtext: UpdateMedicalReportDetailsViewController.catId)
          cell1.checkimage.image = another
  
          print(selectedCells)
      }
      else
      {
  
          selectedCells = []
          cell1.checkimage.image = myimage
  
      }
      return cell1
  
  }
  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  
      let cell = table.cellForRow(at: indexPath) as! catcell
      cell.checkimage.image = myimage
      if cell.isSelected == true
      {
          self.selectedCells.append(indexPath.row)
          cell.checkimage.image = another
      }
  }
  func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
      let cell = table.cellForRow(at: indexPath) as! catcell
      if cell.isSelected == false
      {
  
          self.selectedCells.remove(at: self.selectedCells.index(of: indexPath.row)!)
  
          cell.checkimage.image = myimage
  
      }
  }
  </code></pre>
  
  <p>output : </p>
  
  <p><a href="https://i.stack.imgur.com/ZBjyS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZBjyS.png" alt="enter image description here"></a></p>