在表视图单元格中编辑文本字段的最佳方法 [英] Best approach for editing text fields in a table view cell

查看:105
本文介绍了在表视图单元格中编辑文本字段的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程式中,我有一些观看次数需要到位可编辑。我有 tableviewcells 设置包括启用的 UITextField ,文本可以更改,这是

In my app I've got a number of views that need to be in-place editable. I've got the tableviewcells setup to include a UITextField which is enabled, and the text can be changed and this is fine, it works.

我的问题是什么是最好的方法来跟踪这些?应该:

My question is what is the best approach to keeping track of these? Should I :


  • 保留每个 textfield 的iVar。如果是这样,

    • 如果只是实例化一次,如何确保每个单元格有正确的字段? >
    • Keep an iVar of each textfield. If so then
      • How do I make sure each cell has the correct field if it's only instantiated once?

      • 如何跟踪值?如果单元格走出视图,然后返回,其值将被重置为其原始值,而不是编辑

      • How do I keep track of the values? If the cell went out of view and then back, its values would be reset to its original value and not the edited value.

      您通常使用什么方法?特别是如果有大量的细胞你正在处理。

      What approach do you generally tend to use for this scenario? Especially if there are a large number of cells that you're dealing with.

      推荐答案

      最好的方法是遵循MVC并实现你的模型,在你的case是textfield的值。您所做的是将这些值存储在数组中,并在cellForIndexPath方法中引用数组中的正确值。例如,表的第一行(indexPath.row == 0)将检索数组中的第一个元素。 textField中的更改将记录在数组中的相应元素上。

      The best way is to follow MVC and implement your model, which in your case is the textfield values. What you do is store those values in an array, and in your cellForIndexPath method you reference the correct value in the array. For example, the first row of the table (indexPath.row == 0) would retrieve the first element in the array. Changes in the textField would be recorded on the corresponding element in the array.

      这篇关于在表视图单元格中编辑文本字段的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆