我希望创建一个页面,页面顶部应该有地图,底部是一个5行的表格视图。所以我创建了一个UIViewController,放上了我的MapView,然后放置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
}
}