how to 100 text field in table view ios swift [closed]

梦想与她 提交于 2019-12-27 05:36:27

问题


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 .


回答1:


create data module class as below

class Data {
   var text:String?
}

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.

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
}  

now in text did change method update text in data.text property

func textFieldDidChangeText(textField:UITextField){
    self.data.text =  textField.text
}

set textField text to data.text, so value will be retained even you scroll the application



来源:https://stackoverflow.com/questions/47303118/how-to-100-text-field-in-table-view-ios-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!