Show a main window message box
Alert View will automatically adjust for landscape orientation
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"The username and password entered are not valid"
message:nil
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
;
Show A Message Box
If ActionSheet doesn't auto adjust for landscape orientation check the following:-
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLand scapeRight];
needed in applicationDidFinishLaunching?
Supported interface orientations set to landscape in the app plist file?
Using ActionSheet
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"A Message To Display"
delegate:nil
cancelButtonTitle:@"OK"
destructiveButtonTitle:nil
otherButtonTitles:nil];
[actionSheet showInView:[[self view] window]];
[actionSheet autorelease];
OK Cancel Message Box
In your method that want's to show the action box
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"A Message To Display"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"OK"
otherButtonTitles:nil];
[actionSheet showInView:self.view];
Add the delegate to the classes @interface
@interface #ViewController_iPhone : UIViewController
<UIActionSheetDelegate>
{
Add the delegate method
//*******************************************
//*******************************************
//********** ACTION SHEET DELEGATE **********
//*******************************************
//*******************************************
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
// the user clicked one of the OK/Cancel buttons
if (buttonIndex == [actionSheet destructiveButtonIndex])
{
//----- CLICKED OK -----
}
else if (buttonIndex == [actionSheet cancelButtonIndex])
{
//----- CLICKED CANCEL -----
}
}
Multiple Buttons
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"A Message To Display"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"Test1",@"Test2",nil];
[actionSheet showInView:self.view];
In the actionSheet delegate the buttonIndex starts from 0 being the top most button. If there is a destructiveButtonTitle then this is 0 otherwise it is the first otherButtonTitle.
Useful resources
http://www.iphonedevsdk.com/forum/iphone-sdk-development/8478-simple-message-box-popup.html