I have been working to create a UIAlertView in Swift, but for some reason I can't get the statement right because I'm getting this error:
Could not find an overload for 'init' that accepts the supplied arguments
Here is how I have it written:
let button2Alert: UIAlertView = UIAlertView(title: "Title", message: "message",
delegate: self, cancelButtonTitle: "OK", otherButtonTitles: nil)
Then to call it I'm using:
button2Alert.show()
As of right now it is crashing and I just can't seem to get the syntax right.
Below is the reusable code for alert view and action sheet, Just write one line to show alert anywhere in application
Usage :
You can create a UIAlert using the standard constructor, but the 'legacy' one seems to not work:
try This. Put Bellow Code In Button.
Try this
Here is a pretty simple function of AlertView in Swift :
You have to pass message as a String where you use this function.
If you're targeting iOS 7 and 8, you need something like this to make sure you're using the right method for each version, because
UIAlertView
is deprecated in iOS 8, butUIAlertController
is not available in iOS 7: