试图从数组中删除一个元素我得到这个错误:上下文类型'Int'不能与数组文字一起使用

问题描述 投票:-3回答:2

我在tableView中为reload Cell添加了一个按钮,我希望,当按下按钮时,删除特定单元格上的数组元素但是我收到此错误

上下文类型“Int”不能与数组文字一起使用

@IBAction func reloadCell(_ sender: UIButton) {

        let index = IndexPath(row: sender.tag, section: 0)
        sortedArray.remove(at: [index])    //HERE I GET THE ERROR
        self.tableView.reloadRows(at: [index], with: .right)
    }

我怎么解决呢?

ios arrays swift uitableview swift4
2个回答
2
投票

数组使用Ints作为索引,而不是像IndexPath那样使用tableViews:

sortedArray.remove(at: sender.tag)

0
投票

您不能对数组使用IndexPath类型(您应该使用int类型)ex:

        sortedArray.remove(at: index.row) 
        self.tableView.reloadRows(at: index.row, with: .right)
© www.soinside.com 2019 - 2024. All rights reserved.