ios - 如何从 FooterInSection 中的按钮向 UITableView 中的特定部分添加一行

标签 ios swift xcode

我有一个 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 是这样的

enter image description here

最佳答案

您需要使用以下方法使用单击按钮 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/

相关文章:

ios - 有什么方法可以使用 Xcode 8 beta 将应用程序安装到 iPhone 4?

android - 一直 react native 空屏幕

ios - SWRevealViewController - 防止与后 View 交互

ios - 服务器未返回数据时如何停止 MBProgressHUD 并添加 subview

ios - 使用 Storyboard 设置标签文本时出现短暂滞后

c++ - 使用 Xcode 3.2.6 构建 10.7 Lion 应用程序 - 它们可以工作吗

ios - iOS7 中的奇怪空间

objective-c - 如何使ios 5.1进入xcode模拟器?

ios - 如何判断图片中是否没有文字--MLKit VisionCloudTextRecognizer

iOS View 对象属性与操作方法