Swift UITextField text clears with button action in TableViewCell

China☆狼群 提交于 2019-12-06 00:02:38

I am going to answer my own question ;-)

TextFeilds are only boxes that accommodate some data (text). And since I was reusing the Phonecell each time I add a new row, the text I entered gets erased. This is because it is not "stored/saved" in the user object.

So in my addPhoneButtonAction method, I added this -

@IBAction func addPhoneButtonAction(sender: AnyObject) {
        userInfo?.phones![myIndexPath!.row].country = countryCode.text!
        userInfo?.phones![myIndexPath!.row].number = teleNumber.text!

        self.dataSource?.addUserPhone(userInfo!)
    }

Where myIndexPath is the indexPath of the row :-)

The working sample is here

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