fuzunspm fuzunspm - 1 year ago 92
Swift Question

Swift TableView in a UIView not displaying data

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

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

Here is my code. Thank you

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() {


override func 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


Answer Source

try this:

override func viewDidLoad() {

    // Add this
    tableView.delegate = self
    tableView.dataSource = self
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download