如何动态提交所有cell values
这里是代码。我只是点击了api,然后附加了值,然后显示了所有data
。 现在的问题是如何在文本字段中输入所有变量。
func submitApi(){
SVProgressHUD.show(withStatus: "Loading please wait........")
let url = constatUrl + "url"
print("catagory",url)
Alamofire.request(url, method: .get, parameters:nil, encoding: URLEncoding.default, headers: nil).responseJSON { (response:DataResponse<Any>) in
switch(response.result) {
case .success(_):
SVProgressHUD.dismiss()
if let data = response.result.value{
let json = response.result.value as? [String: Any]
print("theloginAuthValue is ",json!)
let responseStatus = json!["responseStatus"] as! Bool
let responseText = json!["responseText"] as! String
if (responseStatus == true){
self.user_GLosary.removeAll()
self.productLabel.isHidden = false
self.quantyLabel.isHidden = false
self.quntySubmitButton.isHidden = false
let responseData = json!["responseData"] as! [Any]
var index = 0
while index < responseData.count{
let responseArray = responseData[index] as! [String: Any]
let chainId = responseArray["id"] as? String
let chainValue = responseArray["value"] as? String
let folderAppend = FolderGlosaryDetails()
folderAppend.glosaryId = chainId
folderAppend.glosaryName = chainValue
self.user_GLosary.append(folderAppend)
index += 1
}
DispatchQueue.main.async {
self.openingStockTableView.reloadData()
}
}
else if (responseStatus == false){
self.displayAlertMessage(messageToDisplay: responseText)
}
}
break
case .failure(_):
SVProgressHUD.dismiss()
print("faliure",response.result.error!)
self.displayAlertMessage(messageToDisplay: "Something Wrong Please try again")
break
}
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return user_GLosary.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier:"OpeningStockCell",for: indexPath) as! OpeningStockCell
cell.stockLabel.text = user_GLosary[indexPath.row].glosaryName
return cell
}
答案 0 :(得分:0)
您的问题不太清楚,但是我想您想将textfield值存储到tableviewCell的某个数组中,所以下面的代码可能会对您有所帮助。
首先,定义用于存储值的数组。我在这里采用字符串数组,您可以根据需要进行选择。
var arrayValue:Array<String>!
然后将您的文本字段值从单元格存储到数组中。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier:"OpeningStockCell",for: indexPath) as! OpeningStockCell
cell.stockLabel.text = user_GLosary[indexPath.row].glosaryName
// here you can see how you can get value from textfield
arrayValue.append(cell.yourTextField.text!)
return cell
}