【发布时间】:2019-12-01 05:20:28
【问题描述】:
如何将数据加载到我的UITableView?谁能帮我解决这个问题:
为什么不加载到 cellForRowAt
- pPlandDetailId ==>可选(1)
- 司机 ==> 司机姓名:Boonma,Pongpat
- carRegistrtation ==> 汽车注册:60-7620
- StoreLocation ==> ["S.Suratani"]
- pDepartureDateTime ==> ["18/01/2019 20:00"]
import UIKit
class StoreListMainViewController: UIViewController,UITableViewDelegate, UITableViewDataSource{
// TableView
@IBOutlet weak var tableView: UITableView!
var StoreLocation: [String] = []
var getDepartureTime: [String] = []
override func viewDidLoad() {
super.viewDidLoad()
createTableiew()
}//Main Method
// TableView
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 50
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return StoreLocation.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as? cellTableViewCell
cell!.Location.text = StoreLocation[indexPath.row]
cell!.DepartureTime.text = getDepartureTime[indexPath.row]
print("cell!.Location.text ==>\(String(describing: cell!.Location.text) )")
return cell!
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let vc = storyboard?.instantiateViewController(withIdentifier: "gotoTempMonitorStoreList") as? StoreListTempMonitorViewController
self.navigationController?.pushViewController(vc!, animated: true)
}
// Create UI Table view
func createTableiew() -> Void {
tableView.delegate = self
tableView.dataSource = self
}//createTableiew
import UIKit
class cellTableViewCell: UITableViewCell {
@IBOutlet weak var Location: UILabel!
@IBOutlet weak var DepartureTime: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
【问题讨论】:
-
你在哪里查看didload 在你获取数据后你是否批准了你的tableview委托,你应该重新加载你的tableView
-
从您的代码看来,您有多个问题可能导致它无法加载数据。在
cellForRowAt中,您将两个值设置为两个标签,但您用作数据源的StoreLocation数组只是一个字符串数组。首先,你能告诉我jsonResponsePlanDetail是什么吗?也许可以在这里展示一个它的结构示例? -
@Isuru 我更新编码请再次建议我
-
@Nardanong.s 我还没有看到
jsonResponsePlanDetail是什么?顾名思义,它是一个 JSON 响应。你能展示一下它的样子吗? -
@Isuru 我已经更新了代码并显示了 jsonResponsePlanDetail。请给我建议。为什么日期无法加载到 cellForRowAt
标签: ios json swift uitableview