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.
Best Answer
From the
UIAlertView
class:On iOS 8, you can do this:
Now
UIAlertController
is a single class for creating and interacting with what we knew asUIAlertView
s andUIActionSheet
s on iOS 8.Edit: To handle actions:
Edit for Swift 3:
Edit for Swift 4.x: