ios - 触发 IBAction 时更新用于创建 UITableView 的数组数据

标签 ios swift uitableview uibutton uilabel

我创建了一个包含一个 UIImage 和两个 UILabel 的 UITableView。当用户选择该行时,此数据将传递到详细信息 View Controller 。我还在原型(prototype)单元格中成功创建了一个 UIButton,用于更新其中一个 UILabel 的文本。我没有成功尝试在数组中更新此标签,因此此更改反射(reflect)在详细信息 View Controller 上。这是我尝试但没有成功的方法:

@IBAction func updateTableData(_ sender: Any) {
    grinds.removeAll()
    grinds = createArray()
}

这是 repo 协议(protocol)的链接:https://github.com/andrewTuzson/tableViewPractice

在下面的屏幕截图中,左图显示第一个单元格切换为“需要工作”后的表格 View 。右图显示了选择行后加载的详细信息屏幕。

enter image description here

我应该如何解决这个问题?

最佳答案

如果你想在单击按钮时更新 tableViewCell,你应该使模型数组成为全局模型数组以在单击方法中访问它并更新你想要的内容,然后使用委托(delegate)或 NSNotificationCenter 重新加载 tableView

--

在单元格的自定义类中声明一个整数属性,并在 cellForRow 中这样设置

 cell.index = indexpath.row 

关于ios - 触发 IBAction 时更新用于创建 UITableView 的数组数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47956180/

相关文章:

ios - iPhone SDK_表格 View 里面的表格 View

objective-c - 以编程方式将 UIWebView 添加到 UIImageView

ios - 在 Collection View 中使用自定义流布局时添加标题

ios - 过滤 [NSDictionary] 时,闭包错误无法使用类型为 'filter' 的参数列表调用 '((_) -> _)'

ios - Swift:在 GCD 中使用引用类型

ios - 如何获取所选行的索引路径?

ios - 重新安装应用程序后如何从 iCloud 中的文件获取数据?

ios - 如何水平居中 UICollectionView 单元格?

ios - 无法导入已安装的pod模块?

ios - UITableViewCell 缩进仅适用于默认单元格 textLabel