Swift TableView in UIView does not display data

I want to create a page on which the map should be displayed on top and 5 rows of the table below. So, I created a UIViewController, placing my map view, and then set up a TableView. I created myViewController.swift and myTableViewCell.swift

But when I try on the simulator there is no data displayed in the table. Only empty cells. I did not get an 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() {
        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
    }

}
+4
source share
4 answers

try the following:

override func viewDidLoad() {
    super.viewDidLoad()

    // Add this
    tableView.delegate = self
    tableView.dataSource = self
}
+11
source

You must do one of two ways:

tableView.delegate = self
tableView.dataSource = self

viewDidLoad() viewController  - tableView , controlController, , .

+4

UITableView/UICollectionView , :

UITableView, Delegate/Datasource viewcontroller. . .

Click here to view screenshot

+1

.

tableview.dataSource = self tableview.delegate = self

-1

Source: https://habr.com/ru/post/1607799/


All Articles