我有一个 TableView ,它根据数组 (exercisesTableCells) 中的项数加载部分的数量。然后根据该数组 (exercisesSetsTableCells) 中的项目数为每个部分加载行数。两个数组如下:
var exercisesSetsTableCells: [[String]] = [["1","2","3"],["1","2"],["1","2","3","4"],["1","2"],["1","2","3","4"]]
var exercisesTableCells: [String] = ["Bench","Squat","Pull Ups","Curls","Sit Ups"]
我在每个部分的页脚中都有一个按钮,我只想向表格的那个部分添加一行(或者数组的那个索引,具体取决于按钮所在的部分)
我的 table 是这样的
最佳答案
您需要使用以下方法使用单击按钮 subview 的层次结构获取索引路径:
func clickAction(_ sender: AnyObject) {
let button = sender as? UIButton
let cell = button?.superview?.superview as? UITableViewCell
let indexPath = tblview.indexPath(for: cell!)
let newArray = exercisesSetsTableCells.object(at: (indexPath?.row)!) as! NSMutableArray
newArray.add("new data");
exercisesSetsTableCells .replaceObject(at: (indexPath?.row)!, with: newArray);
//reload your tableview here
}
关于ios - 如何从 FooterInSection 中的按钮向 UITableView 中的特定部分添加一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40398104/