我想创建一个页面,顶部应有地图,底部应有 5 行表格视图。所以我创建了 UIViewController 放置我的地图视图然后放置 TableView。我创建了 myViewController.swift 和 myTableViewCell.swift
但是当我在模拟器上尝试时,表格视图上没有显示数据。只有空单元格。我没有收到错误
这是我的代码。谢谢
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
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)