Reputation: 1253
ViewController.swift
@IBOutlet weak var btn_stop: UIButton!
AppDelegate.swift
let viewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("ViewController") as! ViewController
viewController.btn_stop.hidden=false
Error - gives me Fatal error & app Crash
Upvotes: 2
Views: 600
Reputation: 416
Access your ViewController via the rootViewController option:
let viewController = self.window!.rootViewController as! ViewController
viewController.btn_stop.hidden = false // Found nil error
But even in this case it will find nil. The viewController is instantiated but not loaded yet. You should probably unhide the button in the viewDidLoad function of the ViewController.
Upvotes: 1