0

I'm trying to create a map programmatically but all I get is a black screen once I run the app.

Re page 97 in the Big Nerd Ranch iOS Programming 5th Edition, in chapter 6 'Creating a View Programmatically'

I entered the following code in MapViewController.swift

//  MapViewController.swift

import UIKit
import MapKit

// Define a UIViewController subclass named MapViewController

class MapViewController: UIViewController {

    var mapView: MKMapView!

    override func loadView() {
        // create a map view
        mapView = MKMapView()

        // set it as *the* view of this view controller
        view = mapView
    }

    override func viewDidLoad() {
        // Always call the super implementation of viewDidLoad
        super.viewDidLoad()

        print("MapViewController loaded its view.")
    }
}

Once I run the app I get a black screen where the map should be. What's going wrong?

Thanks!

juanjo
  • 3,737
  • 3
  • 39
  • 44
cget
  • 370
  • 1
  • 4
  • 21

1 Answers1

0

I had the same problem.

First, go to Main.storyboard. Then click on the View Controller (the last one with the map icon). Then click on the identity inspector and change the class to MapViewController.