首页 > 解决方案 > 为什么 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"
        }
    ]
}
}

标签: jsonswiftuitableviewreload

解决方案


推荐阅读