I want to add a separated cancel button to my UIAlert.
I know how to do it with UIActionSheet but it should also be possible with UIAlert, right?
var sheet: UIActionSheet = UIActionSheet();
let title: String = "...";
sheet.title = title;
sheet.delegate = self;
sheet.addButtonWithTitle("Cancel");
sheet.addButtonWithTitle("...")
sheet.cancelButtonIndex = 0;
sheet.showInView(self.view);
This will have a ... button and a cancel button which is separated.
So does anyone know how to do this with
var alert = UIAlertController(title: "...", message: "....", preferredStyle: UIAlertControllerStyle.ActionSheet)
?
I'm new to xcode and swift so sorry if this question is dumb or anything...
Its really simple, but works a bit differently to how they used to work. Now you add "actions" to your alerts. These actions are then represented by buttons on the device.
Above is the code needed for a simple cancel button - bear in mind that dismissal of the alert is done automatically so don't put that in your handler. Should you then want to create another button which does something, use the code below:
Hopefully I have understood your question and this answers what you were asking. I will also add that after you have added all of the "actions", you present the alert using the code below:
Hope this helps!