Invalid update: invalid number of sections

Viewed 10691

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections. The number of sections contained in the table view after the update (3) must be equal to the number of sections contained in the table view before the update (3), plus or minus the number of sections inserted or deleted (1 inserted, 0 deleted).'

but i insert 1 and deleted one based on data source what i missed

    self.states?.append(sortedStates) //Update state  property
    if (self.states?.count)! > 3 {
        self.states?.removeFirst()
    }
  self.newsFeedTableView.beginUpdates()
  self.newsFeedTableView.insertSections([(self.states?.count)! - 1], with: .none)
  if (self.states?.count)! > 3 {           
      let statesForoldestStateTime = self.states?.first
      self.newestStateTime = statesForoldestStateTime?.first?.createdAt
      let indexpostion = (self.states?.count)! - 3
     self.newsFeedTableView.deleteSections([indexpostion], with: UITableViewRowAnimation.none)
    }
  self.newsFeedTableView.endUpdates()
1 Answers
Related