I have tow views in my app. A main view(ViewController.swift) and a sidebar(SideBar.swift). If I tapp a button in the sidebar an UIAlertView
should be displayed (I call a function in ViewController.swift). But the app crashes because the main view is nil. Do you know how I can fix this?
My code in the function (display alert):
let alertView = UIAlertController(title: "You need to log in first", message: "To access the special features of the app you need to log in first.", preferredStyle: .Alert)
alertView.addAction(UIAlertAction(title: "Login", style: .Default, handler: { (alertAction) -> Void in
}))
alertView.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))
self.presentViewController(alertView, animated: true, completion: nil)
Crash log:
0x724160 <+60>: bl 0x75961c ; function signature specialization <Arg[0] = Exploded, Arg[1] = Exploded> of Swift.(_fatalErrorMessage (Swift.StaticString, Swift.StaticString, Swift.StaticString, Swift.UInt) -> ()).(closure #2)
-> 0x724164 <+64>: trap