ios - UIView 中的 Swift TableView 不显示数据

标签 ios swift uitableview uiview uiviewcontroller

我想创建一个页面,顶部应该有一个 map ,底部应该有 5 行表格 View 。所以我创建了 UIViewController 放置我的 map View 然后放置 TableView。我创建了 myViewController.swift 和 myTableViewCell.swift

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

这是我的代码。谢谢

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
}

关于ios - UIView 中的 Swift TableView 不显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32628114/

相关文章:

android - React Native - 如何从 componentWillReceiveProps 重定向到登录 View

ipad - UIPopoverController 可以从其 View Controller 的 NIB 获取其大小吗?

ios - tableView.reloadData 和 tableView.reloadRows 有什么区别?

ios - Viewcontroller 无法识别我的变量?

uitableview - Swift - 什么是沮丧?为什么我需要向下转换 tableview 中的单元格?

ios - NSOperation with NSTimer循环如何停止它

ios - 不了解潜在的泄漏

ios - Swift tableView 缓慢和滚动滞后

ios - Swift 解析查询结果未出现在 TableView 中

ios - BOOL UIButton 上的按钮选择