How to access IBOutlet in UITableViewController Class if the IBOutlet is in UIViewController Class

2666 views ios
-4

class AClass: UIViewController,CLLocationManagerDelegate,MKMapViewDelegate {

    @IBOutlet var mapKitView: MKMapView!

    }

class BClass: UITableViewController {

var localAClass=AClass()
localAClass.mapKitView.mapType=MKMapType.standard 

}

Fatal error: Unexpectedly found nil while unwrapping an Optional value

answered question

You linked the IBOutlet ?

Yes of course i linked it

1 Answer

11

In ClassB, you need to use UIStoryboard instantiateViewController(withIdentifier:) to have IBOutlets instantiated.

let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let viewController = 
storyboard.instantiateViewController("AViewController") as! 
AViewController

posted this

Have an answer?

JD

Please login first before posting an answer.