Ios Swift UITextField文本通过TableViewCell中的按钮操作清除
我已经录制了我的屏幕和视频。 细说Ios Swift UITextField文本通过TableViewCell中的按钮操作清除,ios,swift,uitableview,tableviewcell,Ios,Swift,Uitableview,Tableviewcell,我已经录制了我的屏幕和视频。 细说 我有一个tableView部分,其中有一个tableviewcell(PhoneCell),有两个文本字段(一个是pickerview输入,另一个是textfield)和一个Add按钮 当点击Add按钮时,我将一个空电话附加到电话阵列中(重复使用同一个电话单元),并调用tableView.reloadData()方法 问题:( 每当我点击“添加”按钮时,我输入的文本字段文本将被清除。我希望保留它,并最终能够在单击“保存”按钮时保存数据(用户输入的手机数量) @
tableView.reloadData()
方法每当我点击“添加”按钮时,我输入的文本字段文本将被清除。我希望保留它,并最终能够在单击“保存”按钮时保存数据(用户输入的手机数量)
@IBAction func addPhoneButtonAction(sender: AnyObject) {
self.dataSource?.addUserPhone(userInfo!)
}
添加电话按钮操作代码:
func addUserPhone(userData: MyUserData) {
self.user = userData
var emptyPhoneDict:[String:String] = ["country":"", "number":""]
if (user.phones?.count < 4) {
var emptyPhone : MyUserPhoneNumber = MyUserPhoneNumber(dictionary: emptyPhoneDict)!
emptyPhone.country = ""
emptyPhone.number = ""
user.phones?.append(emptyPhone)
}
}
编辑(添加了cellForRowAtIndexPath)
编辑2(添加了addPhoneButtonAction)
其中,dataSource
是PhoneCellDataSource协议类型的变量
protocol PhoneCellDataSource : class {
func fetchCountryTeleCodeList(completion:((XtraResult<NSArray, XtraError>) -> Void))
func addUserPhone(userData: MyUserData)
}
协议PhoneCellDataSource:类{
func fetchCountryTelecoodeList(完成:((XtraResult)->Void))
func addUserPhone(userData:MyUserData)
}
我可以根据需要共享更多输入/代码。请帮助。提前感谢!我将回答我自己的问题;-) TextFeild仅是容纳某些数据(文本)的框。由于我每次添加新行时都会重复使用Phonecell,所以输入的文本会被删除。这是因为它未在用户对象中“存储/保存” 所以在我的addPhoneButtonAction方法中,我添加了这个-
@IBAction func addPhoneButtonAction(sender: AnyObject) {
userInfo?.phones![myIndexPath!.row].country = countryCode.text!
userInfo?.phones![myIndexPath!.row].number = teleNumber.text!
self.dataSource?.addUserPhone(userInfo!)
}
其中myIndexPath是行的indexPath:-)
正在工作的为解决方案lohit创建了漂亮的GIF…:)请您输入CellForRowatineXpath代码好吗?@Dherajd:谢谢:-)我在我的邮箱中添加了CellForRowatineXpathquestion@LohithKorupolu您能否显示
addPhoneButton
的按钮操作?addPhoneButton还需要了解问题。完成!添加了addPhoneButtonAction
protocol PhoneCellDataSource : class {
func fetchCountryTeleCodeList(completion:((XtraResult<NSArray, XtraError>) -> Void))
func addUserPhone(userData: MyUserData)
}
@IBAction func addPhoneButtonAction(sender: AnyObject) {
userInfo?.phones![myIndexPath!.row].country = countryCode.text!
userInfo?.phones![myIndexPath!.row].number = teleNumber.text!
self.dataSource?.addUserPhone(userInfo!)
}