json - 为什么 tableview 没有在 swift 中重新加载 JSON 数据
问题描述
我的屏幕看起来像这样
在这里,如果我添加所有字段并单击提交按钮,那么我需要在 tableview 中显示该数据.. 这即将到来但如果我停止构建并再次运行,则 tableview JSON 数据没有显示,为什么?
代码:
class WithdrawFundsVC: UIViewController, UITableViewDelegate, UITableViewDataSource
{
private var withdrawData = WithdrawModel(dictionary: NSDictionary()){
didSet {
tableView.reloadData()
}
}
override func viewWillAppear(_ animated: Bool) {
withdrawServicecall()
tableView.reloadData()
}
func withdrawServicecall(){
if bankmode == "B"
{
parameters = ["payment_method" : "B", "bank_name" : nankNameTextfield.text, "bank_account_no" : accNumTextField.text, "bank_account_holder_name" : accNameTextfield.text, "bank_code" : bankCOdeTextField.text, "bank_amount" : amountTextField.text] as [String : Any]
}
if bankmode == "P"{
parameters = ["payment_method" : "P", "paypal_email" : paypalEmail.text, "paypal_amount" : paypalAmount.text] as [String : Any]
}
APIReqeustManager.sharedInstance.serviceCall(param: parameters as [String : Any], method: .post, loaderNeed: false, loadingButton: nil, needViewHideShowAfterLoading: nil, vc: self, url: CommonUrl.withdrawal_money, isTokenNeeded: true, isErrorAlertNeeded: true, isSuccessAlertNeeded: true, actionErrorOrSuccess: nil, fromLoginPageCallBack: nil) { [weak self] (resp) in
if let code = ((resp.dict?["result"] as? [String : Any])){
let success = code["status"] as? [String : Any]
let message = success?["message"] as? String
if message == "Success"{
print("result of withdrawal \(code)")
}
}else{
self?.view.makeToast(CommonMessages.somethingWentWrong)
}
self?.withdrawData = WithdrawModel(dictionary: resp.responseDict as? NSDictionary ?? NSDictionary())
}
}
@IBAction func submitBtnaction(_ sender: Any) {
withdrawServicecall()
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return withdrawData?.result?.withdrawal_list?.count ?? 0
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "WithdrawfundTableViewCell", for: indexPath) as! WithdrawfundTableViewCell
let indexData = withdrawData?.result?.withdrawal_list?[indexPath.row]
cell.transferModelabel.text = "\(indexData?.payment_method ?? "") Transfer"
return cell
}
将此代码数据成功添加到 tableview.. 但如果我停止并再次运行.. tableview 没有显示。为什么?
请指导我
编辑:来自服务器的 JSON 响应
{
"jsonrpc": "2.0",
"result": {
"status": {
"code": "-36739",
"message": "Success",
"meaning": "Withdrawal request is placed successfully and user wallet is updated with latest balance"
},
"withdrawal_list": [
{
"id": 16,
"user_id": "6",
"date": "2021-07-31",
"amount": "5",
"payment_method": "Bank",
"paypal_email": null,
"bank_name": "ABC",
"bank_acc_holder_name": "Anny B",
"bank_acc_no": "123ABcd",
"bank_code": "123",
"status": "N",
"payment_date": null,
"notes": null,
"created_at": "2021-07-31 02:22:13",
"updated_at": "2021-07-31 02:22:13"
}
]
}
}
解决方案
推荐阅读
- android - 在 Jetpack Compose 中重新定位 Toast
- android-studio - 评估项目 ':library' 时出现问题
- typescript - 类型保护是否仅在返回 true 时缩小类型?
- classification - 特征重要性可以用来解释模型预测的“为什么以及哪个特征有贡献”?
- uwp - 为 UWP 平台引发错误的平台特定 xaml
- java - 应用更新后Android webview缓存丢失
- flutter - 如何在颤动中使用来自另一个类的字符串数据
- snowflake-cloud-data-platform - Snowflake 支持哪些数据源?
- google-sheets - Google表格有没有办法将数组保存在单个单元格中并使用索引来查找矩阵的值?
- c++ - 关闭窗口时QTimer不会停止