如何在表格视图中显示 100 个文本字段 ios swift [英] how to 100 text field in table view ios swift
问题描述
表格视图中的单元格数量 100并且每个单元格都有一个文本字段,当我滚动时,值应该出现在文本框中.另一个 LABEL 在表视图中显示没有 OF 索引.
number of cell in table view 100 and every cell having a text field and when ever i am scrolling value should be present in text box . and one another LABEL show no OF index in Table view .
推荐答案
创建数据模块类如下
class Data {
var text:String?
}
然后在数组中添加 100 个对象并从数组加载 tableview.现在创建自定义单元格 &在自定义单元格类中引用文本字段.在此类中的 textField 上实现文本更改的观察者.
then add 100 objects in array and load tableview from array. Now create custom cell & take reference of textfield in custom cell class. Implement observer for text change on textField in this class.
现在在自定义单元格中编写如下函数
Now write function as below in custom cell
func configureCell(data:Data){
}
从该函数中当前索引处的索引路径传递对象的行的单元格中调用此函数.
call this function from cell for row at index path pass object at current index in this function.
现在在自定义单元格中声明局部变量,该变量将保存 then 对象的引用,如下所示.
Now declare local variable in custom cell which will hold reference of then object as below.
var data:Data?
func configureCell(data:Data){
self.data = data
self.textField.text = data.text
}
现在在文本中确实改变方法更新 data.text 属性中的文本
now in text did change method update text in data.text property
func textFieldDidChangeText(textField:UITextField){
self.data.text = textField.text
}
将 textField 文本设置为 data.text,这样即使滚动应用程序也会保留值
set textField text to data.text, so value will be retained even you scroll the application
这篇关于如何在表格视图中显示 100 个文本字段 ios swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!