Message Box (Action Sheet) General

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];
		[alert show];

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

Creating an about box

Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.
comments powered by Disqus
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.