UIAlertView without Cancel Button?
Asked Answered
I

2

6

I am trying to create a UIAlertView that has 3 options and no "cancel" button, but when I do this, it always styles "Button 3" as a cancel button. Is there any way to avoid this?

UIAlertView *alertView= [[UIAlertView alloc] initWithTitle:@"Select One" message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"Button 1",@"Button 2", @"Button3", nil];
Intoxicant answered 30/8, 2011 at 22:5 Comment(2)
From the documentation, it looks like there isn't a way surprisingly. I'm still playing with it, but it seems that the cancel button defaults to one of the other buttons.Indetermination
At this point I have gone with an Action Sheet. Not really the way I want to do it, so if anyone knows how to make the Alert View work, please feel free to chime in.Intoxicant
N
6

This is a post about how to change the position of the cancel button. Also, if you have only 1 button in the UIAlertView, then setting:

_alertView.cancelButtonIndex = -1;

Will make the button appear as a non-cancel type button. As far as I can tell though, once you have more than 1 button, the UIAlertView forces the last button to be the cancel button. Looking through the reference may give you a clue about how to set the properties up to achieve this, but I'm not too sure. Hope that Helps!

Nieman answered 30/8, 2011 at 23:26 Comment(0)
S
8

I did differently, passing cancelButtonTitle argument as nil.

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Title"
                           message:@"Message here"
                           delegate:self
                           cancelButtonTitle:nil
                           otherButtonTitles:@"OK", nil];
Schizophrenia answered 10/7, 2015 at 13:33 Comment(0)
N
6

This is a post about how to change the position of the cancel button. Also, if you have only 1 button in the UIAlertView, then setting:

_alertView.cancelButtonIndex = -1;

Will make the button appear as a non-cancel type button. As far as I can tell though, once you have more than 1 button, the UIAlertView forces the last button to be the cancel button. Looking through the reference may give you a clue about how to set the properties up to achieve this, but I'm not too sure. Hope that Helps!

Nieman answered 30/8, 2011 at 23:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.