gpt4 book ai didi

ios - 点击按钮时如何获取添加的行文本字段文本?

转载 作者:行者123 更新时间:2023-11-29 05:17:35 25 4
gpt4 key购买 nike

我在表格 View 中为特定类别添加了额外的行,我需要在点击按钮时添加行文本字段 FinalSearchValue。

我有两个文本字段 cell?.searchTextfield.text = AlertParam(这是从 json 获取的手机号码)和 cell?.searchTextfield.text = "Amount" (添加了额外的行金额)如果我在这两个文本字段中输入文本,我需要在两个变量中输入两个值,在 payButton 中如何实现这一点。

enter image description here

我是这样的;

var cell : BillerTableViewCell?
var finalSearchValue : String = ""
var finalSearchValueAmnt : String = ""

如果我在 FinalSearchValueAmnt 中输入 amount 值,并在 FinalSearchValue 中输入 phnum,我需要这两个值,但我只获得最后一个文本字段值,为什么?请帮忙。

这是代码:

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

if indexPath.section == 0 {

cell = tableView.dequeueReusableCell(withIdentifier: "textfieldCell", for: indexPath) as? BillerTableViewCell
cell?.searchTextfield.delegate = self

if self.rowCount! - 1 >= indexPath.row
{
if let customerDetail = selectedBiller?.bcustomerparms[indexPath.row] {

alertParam = customerDetail.paramName
cell?.searchTextfield.text = alertParam
if var priceOfProduct: String = customerDetail.minLength {
alertMinL = Int(priceOfProduct)
}
if var priceOfProduct: String = customerDetail.maxLength {
alertMaxL = Int(priceOfProduct)
}
cell?.searchTextfield.addTarget(self, action: #selector(searchPhoneEditingChanged(textField:)), for: .editingChanged)
}
else{
print("no tf")
cell?.searchTextfield.text = "missing"
}
}
else{
cell?.searchTextfield.text = "Amount"
cell?.searchTextfield.addTarget(self, action: #selector(searchAmountEditingChanged(textField:)), for: .editingChanged)

}
}
return cell!
}


@objc func searchEditingChanged(textField: UITextField) {
finalSearchValue = textField.text!
self.textCount = self.finalSearchValue.count
}

@objc func buttonClicked(sender: UIButton) {
if self.finalSearchValue.isEmpty{
AlertFun.ShowAlert(title: "", message: "Please enter \(self.alertParam!)", in: self)
}
else if self.textCount ?? 0 < self.alertMinL ?? 0{
AlertFun.ShowAlert(title: "", message: "\(self.alertParam!) not lessthen \(self.alertMinL!)", in: self)
}
else if self.textCount ?? 0 > self.alertMaxL ?? 0{
AlertFun.ShowAlert(title: "", message: "\(self.alertParam!) not graterthen \(self.alertMaxL!)", in: self)
}
if self.finalSearchValueAmnt.isEmpty{
AlertFun.ShowAlert(title: "", message: "Please enter Amount", in: self)
}
else{
billerFetchService()
}
}

如何在一个变量中获取 cell?.searchTextfield.text = "Amount" FinalSearchValue,请帮助我完成上述代码。

最佳答案

问题:如何从文本字段获取值。

解决方案:我创建了一个两个操作方法。第一个用于电话号码,第二个用于金额。

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

if indexPath.section == 0 {

cell = tableView.dequeueReusableCell(withIdentifier: "textfieldCell", for: indexPath) as? BillerTableViewCell

if self.rowCount! - 1 >= indexPath.row
{
if let customerDetail = selectedBiller?.bcustomerparms[indexPath.row] {

alertParam = customerDetail.paramName
cell?.searchTextfield.text = alertParam
cell?.searchTextfield.addTarget(self, action: #selector(searchPhoneEditingChanged(textField:)), for: .editingChanged) // for phone number

}

}
else{
cell?.searchTextfield.text = "Amount"
cell?.searchTextfield.addTarget(self, action: #selector(searchAmountEditingChanged(textField:)), for: .editingChanged) // for amount

}
}
return cell!
}

// Action 方法

@objc func searchPhoneEditingChanged(textField: UITextField) {
finalSearchValue = textField.text! // used to store phone Number
self.textCount = self.finalSearchValue.count
}

@objc func searchAmountEditingChanged(textField: UITextField) {
finalSearchValueAmnt = textField.text! // used to store Amount.
}

//检索两个值

@objc func buttonClicked(sender: UIButton) {
//Now here you can get both the values.
print(finalSearchValueAmnt)
print(finalSearchValue)

}

关于ios - 点击按钮时如何获取添加的行文本字段文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59017627/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com