Ios 重新加载表数据时出现“NSInternalInconsistencyException”

Ios 重新加载表数据时出现“NSInternalInconsistencyException”,ios,swift,Ios,Swift,我正在尝试为我的应用程序使用两个列表,一个用于保存我关注的用户,另一个用于保存我的关注者。然后我有一个分段控件在两个列表之间进行选择,最后我创建了另一个列表,它实际上与UITableView相关,所以我认为这样做更容易 当我从一个列表切换到另一个列表时,问题就出现了: func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return tableList.count

我正在尝试为我的应用程序使用两个列表,一个用于保存我关注的用户,另一个用于保存我的关注者。然后我有一个分段控件在两个列表之间进行选择,最后我创建了另一个列表,它实际上与UITableView相关,所以我认为这样做更容易

当我从一个列表切换到另一个列表时,问题就出现了:

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
    return tableList.count
}

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "userCell", for: indexPath) as! UserCell

    let user = tableList[indexPath.row]
    cell.userUser.text = user.userName

    return cell
}

@IBAction func switchValue(_ sender: Any) {
    section = segmentedControl.selectedSegmentIndex

    switch section {
    case 0:
        showFollowers()
    case 1:
        showFollowing()
    default:
        return
    }
}

func showFollowers () {
    tableList.removeAll()
    tableView.reloadData()

    if !followersList.isEmpty {
        for users in followersList {
            tableList.append(users)
            tableView.insertRows(at: [IndexPath(row: tableList.count - 1, section: 0)], with: .fade)
        }
    }
}

func showFollowing (){
    tableList.removeAll()
    tableView.reloadData()

    if !followingList.isEmpty {
        for users in followingList {
            tableList.append(users)
            tableView.insertRows(at: [IndexPath(row: tableList.count - 1, section: 0)], with: .fade)
        }
    }
}
这就是我得到的:

* Assertion failure in -[UITableView _endCellAnimationsWithContext:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKitCore_Sim/UIKit-3901.4.2/UITableView.m:2071
* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'attempt to delete row 1 from section 0 which only contains 0 rows before the update'
我看过UITableView(u endcell animations with context),我不知道这意味着什么,但它说的是动画,所以我想如果我简化代码,它可能会起作用:

func showFollowers () {
    tableList = followersList
    tableView.reloadData()
}

func showFollowing (){
    tableList = followingList
    tableView.reloadData()
}
我得到了什么?同样的错误。有人能帮我吗

笔记
在调试应用程序并找出问题的实际位置时,我发现只有在列表之间快速切换时,问题才会出现。说真的,我不是在开玩笑。如果我慢慢地按下按钮,它会完全正常。

慢慢地,我的意思是我按下按钮,然后我等待2-3秒,然后再次按下它。我不知道你的第二段代码是如何导致相同的异常,因为它没有调用deleteRows。您是否在代码中的其他地方调用该函数?如果只是重新加载,则不调用insert/delete。此外,请在部分中显示您的行数:code@Paulw11首先,谢谢你的建议。因为动画,我想使用第一个代码,但是如果你说第二个更好,我会使用它。另一方面,它抛出了相同的错误:。。。原因:“尝试删除第0节中的第1行,该节在更新之前仅包含0行”。@Paulw11我还在问题中添加了您要求的函数。