简体   繁体   English

Swift:如何更新行

[英]Swift: How to update row

In the code below is the code that I used to save the data in JSON whenever any change is made but the problem is that I want to save only that field that is edited and not all fields.在下面的代码中,每当进行任何更改时,我都用来将数据保存在 JSON 中,但问题是我只想保存已编辑的字段,而不是所有字段。
ps: I have use Eureka Forms. ps:我使用过尤里卡表格。

One way to do it is to store a set of rows that are edited.一种方法是存储一组已编辑的行。

var editedRowTags: Set<String>()

In the onChange callback of each row, add the row's tag into the set:在每行的onChange回调中,将行的标签添加到集合中:

editedRowTags.insert(row.tag!)

In the save button's IBAction , loop through the set and get the rows using the tags, then addRequest the values.在保存按钮的IBAction ,循环遍历集合并使用标签获取行,然后addRequest值。

for tag in editedRowTags {
    let row = form.rowBy(tag: tag)
    requestsArray.addRequest(withValue: row.baseValue!, forFieldName: tag)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM