ios - 如何将数据加载到 TableView 中

标签 ios json swift uitableview

如何将数据加载到我的 UITableView 中?谁能帮我解决这个问题: 为什么不加载到 cellForRowAt

  • pPlandDetailId ==>可选(1)
  • 司机 ==> 司机姓名:Boonma,Pongpat
  • carRegistrttation ==> Car Registrttation:60-7620
  • StoreLocation ==> ["S.Surathani"]
  • 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)
    }
}

最佳答案

在您收到数据的地方重新加载 tableview tableView.reload()

关于ios - 如何将数据加载到 TableView 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57159455/

相关文章:

ios - 使用 Swift 触摸任意位置关闭 iOS 键盘

ios - NSRangeException - 无法删除观察者

ios - UIPageViewController 的 UIPageControl 在滚动到下一个 View Controller 时有时不会更新

android - 在 Android 设备 Xamarin 上调试时请求无效

Python pandas to_json() 格式无效

swift - 访问字符串键以显示获取图像(Swift)

xcode6 - Swift 1.2 中的 .getBytes() 带来了麻烦

iOS - 自定义节标题边界问题

iphone - iOS7 主屏幕模式下的 Cookie

javascript - 如何计算该问答流程的最短和最长路径?