Как сделать insertRows? в моей ситуации

swift

#1

Слушайте столкнулся с такой проблемой! У меня три массива , для каждого массива свой раздел в общем сегмент контроль происходит. Я вот для каждого массива вот так назначил массив. Вот мой код

   var soccerString = [Soccer]()
   var basketString = [Basketball]()
   var tennisString = [Tennis]()

 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        var returnSport = 0
        switch (segmentControl.selectedSegmentIndex) {
        case 0 :
            
            returnSport = soccerString.count
            break
        case 1 :
            returnSport = basketString.count
            break
        case 2 :
            returnSport = tennisString.count
            break
        default :
            break
        }
        
        return returnSport
        
    }

Я брал создавал функцию и в ней писал

 soccerString.insert(Soccer(), at : 0)
     let indexPath = IndexPath(row: 0, section: 0)
        tableView.insertRows(at: [indexPath], with: .automatic)

и в конце ставил
tableView.reloadData()
Но изменения не происходили.


#2

На это сообщение поступили жалобы от участников сообщества, поэтому оно временно скрыто.


#3

ну да , я вот сделал так

  func insertRowNewMatch () {
        tableView.beginUpdates()
        tableView.insertRows(at: [IndexPath(row: soccerString.count-1, section: 0)], with: .none)
        tableView.endUpdates()
    }
но мне выдает ошибку .

я вот эту часть передал по другому :

 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
                if segmentControl.selectedSegmentIndex == 0 {
                    return soccerString.count
                }
                else if segmentControl.selectedSegmentIndex == 1 {
                    return basketString.count
                    
                
                }
                else if segmentControl.selectedSegmentIndex == 2 {
                return tennisString.count
            
            }
            return 0
        }

но мне все равно выдает ошибку

" The number of rows contained in an existing section after the update (0) must be equal to the number of rows contained in that section before the update (0), plus or minus the number of rows inserted or deleted from that section (1 inserted, 0 deleted) and plus or minus the number of rows moved into or out of that section (0 moved in, 0 moved out).’