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

2666 views ios

class AClass: UIViewController,CLLocationManagerDelegate,MKMapViewDelegate {

    @IBOutlet var mapKitView: MKMapView!


class BClass: UITableViewController {

var localAClass=AClass()


Fatal error: Unexpectedly found nil while unwrapping an Optional value

answered question

You linked the IBOutlet ?

Yes of course i linked it

1 Answer


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! 

posted this

Have an answer?


Please login first before posting an answer.