Xcode 6 or iOS 8 Bug: UIAlertController Not Showing Message? - swift

In my view controller I have the following code to create a UIAlertController:
var avc = UIAlertController(title: "Location", message: "Please Enter A Location", preferredStyle: UIAlertControllerStyle.Alert)
self.navigationController!.presentViewController(avc, animated: true, completion: nil)
Running it in the simulator, I see
Pretty sure this is a bug in Xcode 6 beta 7 or swift? Ideas?

Found the answer, I'm supposed to add an action to the UIAlertController for the message to be displayed:
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))

Related

UIAlertController (ActionSheet) - Unable to simultaneously satisfy constraints [duplicate]

This question already has answers here:
Swift default AlertViewController breaking constraints
(12 answers)
Closed 3 years ago.
I'm getting this warning every time an UIAlertController action sheet is presented in a simulated phone. The code is nothing fancy.
let action1 = UIAlertAction(title: "Action 1", style: .default) { _ in }
let action2 = UIAlertAction(title: "Action 2", style: .default) { _ in }
let cancel = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
let alert = UIAlertController(title: "title", message: "message", preferredStyle: .actionSheet)
alert.addAction(action1)
alert.addAction(action2)
alert.addAction(cancel)
self.present(alert, animated: true)
I'm running Xcode 10.2 (10E125), Swift 5. The constraint seems out of my control but please advise if I'm doing something wrong.
Screenshot of IB showing the icons for constraint-manipulating menus. You can also click on the constraints themselves to edit or delete them.
Check out the various drop-down menus.

Error in console using UIAlertAction Xcode 7.3 beta

I am trying to print the error to the user using alertview.
Here is my code :::
if error != nil{
let DisplayAlert = UIAlertController(title: "Error!!", message: error?.description, preferredStyle: .Alert)
DisplayAlert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
}
When I run the code I see the following in the console and I do not see any alert displayed to user.
"Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior"
What should i do to fix this issue.? Pls help.
Thanks !!!
Looks like you have forgot to present the alert
if error != nil{
let DisplayAlert = UIAlertController(title: "Error!!", message: error?.description, preferredStyle: .Alert)
DisplayAlert.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
self.presentViewController(DisplayAlert, animated: true, completion: nil)
}

Using alertview in ios 9 with swift

When I user alertview in ios 9 with swift, compiler shows this warning message:
UIAlertView' was deprecated in iOS 9.0: UIAlertView is deprecated. Use UIAlertController with a preferredStyle of UIAlertControllerStyleAlert instead
try using this code
let alert = UIAlertController(title: "TITLE", message: "MESSAGE", preferredStyle: UIAlertControllerStyle.Alert)
let okAction = UIAlertAction(title:"OK", style: UIAlertActionStyle.Cancel, handler: { (action) -> Void in
})
alert.addAction(okAction)
dispatch_async(dispatch_get_main_queue(),{
self.presentViewController(alert, animated: true, completion: nil)
})

Alert makes app crash on phone but not in simulator

I am using the following function to display an alert with an "ok" and a "cancel" Button:
func displayModalDialog(#title: String, message: String, yesHandler: ((UIAlertAction!) -> Void)?, noHandler: ((UIAlertAction!) -> Void)?) {
var alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Default, handler: yesHandler))
alert.addAction(UIAlertAction(title: "Yes", style: UIAlertActionStyle.Default, handler: noHandler))
self.presentViewController(alert, animated: true, completion: nil)
}
This function is part of view controller which is the parent class of most view controllers in my app. When I start my app in the Simulator everything works fine and the alert is displayed with the specified parameters. However when I try to run it on a phone (4s with iOS7 and 5 with iOS8 tested) it crashes on the line:
var alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
giving me a EXC_BAD_ACCESS error. Using exceptionBreakpoints did not reveal any additional information.
Hope anyone has help - thanks!

App crashing when UIAlertController is displayed

I have just changed my deployment target from iOS 8 to 7 so I am testing my app on iOS 7 for the first time.
I am having an issue with the UIAlertController crashing my app when it is called. It works absolutely fine on iOS 8 however doesn't work at all on iOS 7.
Here is the code I am using:
#IBAction func resetAllButton(sender : AnyObject) {
var alert = UIAlertController(title: "Start Over", message: "Are you sure you want to start over? This will erase your budget and all transactions.", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "I'm sure!", style: UIAlertActionStyle.Default, handler:{ (ACTION :UIAlertAction!)in
self.resetView()
}))
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
UIAlertController is only available on iOS 8 or higher. You need to use a UIAlertView to present the alert on iOS 7.