views:

693

answers:

5

Is it possible to have alert view buttons above each other instead of next to each other?

+2  A: 

Not without customizing (subclassing) the UIAlertView class. If you wanted to take this route, you'd have to alter the UIAlertView's layoutSubviews method to place its buttons in different locations.

Tim
+1  A: 

If there are enough buttons or the text is too long, the buttons will display above each other instead of next to each other. UIKit decides for you and there's no way to control it.

Martin Gordon
When I tried this, the second button did not move.. it only showed as much text as it could and cut off the rest. The button did not move above the other one.
Steve
+1  A: 

If you want to risk it, or you're not aiming at the AppStore, you could use the undocumented setNumberOfRows method on UIAlertView.

- (void) showAlert 
{ 
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Your title" 
                          message:@"Your message" delegate:self  
                          cancelButtonTitle:nil 
                          otherButtonTitles:@"One", @"Two", @"Three", nil]; 
    [alert setNumberOfRows:3]; 
    [alert show]; 
 }
Jane Sales
Will they really reject an app for using undocumented API methods? Or will they simply not guarantee any particular result or future compatibility? I've been curious about this (and various other) undocumented, yet helpful, API methods.
LucasTizma
They will reject it, outright. It has happened to me and many other developers. It is a fact of the app store that you must accept if you wish to continue down that path.
Jasarien
There's even an application uploader tool now, that I suspect does these kind of tests before uploading, to give you a much quicker rejection :-)
JBRWilkinson
This was written a long time ago. I agree, don't even go there unless you're not aiming at the App store.
Jane Sales
A: 

@Lucas - yes they will really reject an app for calling setNumberOfRows: on UIAlertView. My app got through in many updates until they finally rejected and update for this reason.

@Martin - it actually appears to truncate the text that won't fit.

alan
@alan-why they will reject the app for using [alert setNumberOfRows:3]; is this an Undocumented API call?
Rahul Vyas
yes - it is a private method on UIAlertView
alan
A: 

You can use UIActionSheet

Take a look in here at the samples :)

http://www.timeister.com/2010/06/objc-show-alert-iphone/


Good luck,

Adrian

Adrian Pirvulescu
Doesn't UIActionSheet slide up from the 'bottom' of the screen? Is there a way to make it appear in the middle of the screen, like UIAlertView?
JBRWilkinson