UIView中的Swift TableView不显示数据 [英] Swift TableView in a UIView not displaying data

查看:556
本文介绍了UIView中的Swift TableView不显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个页面,其顶部应有地图,底部有5行tableview。所以我创建了UIViewController,然后把我的Map View放到TableView中。我创建了myViewController.swift和myTableViewCell.swift

I want to create a page which should have a map on the top and 5 row tableview at the bottom. So i created UIViewController put my Map View then put TableView. I created myViewController.swift and myTableViewCell.swift

但是当我尝试使用模拟器时,没有数据显示在tableview上。只有空单元格。我没有收到错误

But when i try on simulator no data showing on tableview. Only empty cells.I received no error

这是我的代码。谢谢

import UIKit
import MapKit

class myViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {

    @IBOutlet weak var mapView: MKMapView!

    var labels = ["some arrays"]

    var images = ["some image names in an array"]

    @IBOutlet weak var tableView: UITableView!

    override func viewDidLoad() {
        super.viewDidLoad()

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
    }

    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }

    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return labels.count
    }

    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("mySegue", forIndexPath: indexPath) as! myTableViewCell

        cell.myCellLabel.text = labels[indexPath.row]
        cell.myCellImage.image = UIImage(named: images[indexPath.row])

        return cell
    }

}


推荐答案

试试这个:

override func viewDidLoad() {
    super.viewDidLoad()

    // Add this
    tableView.delegate = self
    tableView.dataSource = self
}

这篇关于UIView中的Swift TableView不显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆