gpt4 book ai didi

ios - 重新加载 TableView 后未获取 TableView 数据

转载 作者:搜寻专家 更新时间:2023-11-01 06:26:13 24 4
gpt4 key购买 nike

我正在使用 AlamofireSwiftyJSOn 调用 api,我正在创建用于在 tableview 中显示数据的模型类,这是我的回应

响应

{
"inspections_todays_data" : [

],
"message" : "Successfully.",
"success" : "1",
"inspections_future_data" : [

],
"inspections_overdue_data" : [
{
"notes" : "Test",
"surveyor_id" : "8",
"longitude" : null,
"time" : "08:00",
"address3" : null,
"county" : "carlow",
"client_id" : "3",
"house_num" : "test street",
"eircode" : "12345",
"address1" : "test area",
"date_inspected" : "2019-01-10",
"address2" : "test city",
"country" : "Ireland",
"latitude" : null,
"name" : "test street",
"property_id" : "22"
}
]
}

正如您在响应中看到的,我有三个数组,我正在获取 inspections_overdue_data 数组,我已成功获取但无法在 tableview 上显示

这是我的代码

代码

  func OverdueList(){
let preferences = UserDefaults.standard
let uid = "u_id"
let acTkn = "acc_tkn"

let u_ID = preferences.object(forKey: uid)
let A_Token = preferences.object(forKey: acTkn)

let params = ["user_id": u_ID!, "access_token": A_Token!]
print(params)
Alamofire.request(inspectionsList, method: .post, parameters: params).responseJSON(completionHandler: {(response) in
switch response.result{
case.success(let value):
let json = JSON(value)
print(json)
let data = json["inspections_overdue_data"]
print(data)
if data == []{
self.viewNodata.isHidden = false
}else{
data.array?.forEach({ (iunOverDue) in
let iOveList = OvedueModel(surveyor_id: iunOverDue["surveyor_id"].stringValue, country: iunOverDue["country"].stringValue, time: iunOverDue["time"].stringValue, address2: iunOverDue["address2"].stringValue, notes: iunOverDue["notes"].stringValue, house_num: iunOverDue["house_num"].stringValue, name: iunOverDue["name"].stringValue, address1: iunOverDue["address1"].stringValue, eircode: iunOverDue["eircode"].stringValue, date_inspected: iunOverDue["date_inspected"].stringValue, property_id: iunOverDue["property_id"].stringValue, county: iunOverDue["county"].stringValue, client_id: iunOverDue["client_id"].stringValue)
print(iOveList)
self.overDueData.append(iOveList)
})

self.tblOvedue.reloadData()
}

case.failure(let error):
print(error.localizedDescription)
}

})
}

我还通过 Storyboard添加了委托(delegate)和数据源,但我仍然无法在此处显示数据是我的 tableview 方法

   func numberOfSections(in tableView: UITableView) -> Int {
return 0
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return overDueData.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell") as! OverDueTableViewCell
let name = overDueData[indexPath.row].name
let address1 = overDueData[indexPath.row].address1
cell.lblTitle.text = "\(name) \(address1)"
return cell
}

最佳答案

numberOfSections 返回 0,如果您想查看任何内容,您必须至少返回 1。

提示:如果您只有 1 个部分,则可以省略它,因为 1 是默认返回值。

关于ios - 重新加载 TableView 后未获取 TableView 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54217039/

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