---
title: "iphone 确认框与提示框"
author: "wilent"
date: "2012-08-25T23:35:52Z"
tags: []
categories: ["移动开发"]
slug: "iphone"
draft: false
lastmod: "2012-08-25T23:35:52Z"
id: 1663000
url: "https://wilent.iteye.com/blog/1663000"
---

首先Controller需要遵守UIActionSheetDelegate协议，如：

 

```
@interface SampleController : UIViewController<UIActionSheetDelegate> 
```

   Controller实现中可以这样触发确认框：

 

```
   UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Are you sure?"
									        delegate:self
										cancelButtonTitle:@"No way!"
										destructiveButtonTitle:@"Yes,I'm Sure!"
										otherButtonTitles:nil
					        ];
   [actionSheet showInView:self.view];
   [actionSheet release];
```

    Controller确认框事件：

 

```
-(void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex{
	if(buttonIndex !=[actionSheet cancelButtonIndex]){
		NSString *msg = nil;
		if(nameField.text.length>0){
			msg = [[NSString alloc] initWithFormat:@"You can breathe easy ,%@,everything went OK>",nameField.text];
		}else{
			msg = @"You can breathe easy,everything went OK.";
		}
		UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"something was" message:msg delegate:self cancelButtonTitle:@"phew!" otherButtonTitles:nil];
		[alert show];
		[alert release];
		[msg release];
	}
}
```