iphone中常用的消息提示控件,就是UIActionSheet和UIAlertView了,在Web开发中,UIActionSheet就像是confirm(),而UIAlertView就像是alert()一样
UIActionSheet
UIAlertView
但在iphone中,这两个控件的功能可以自定义
定义两个控件事件方法
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController
- (IBAction)showActionSheet:(id)sender;
- (IBAction)showAlertView:(id)sender;
@end
实现事件
- (IBAction)showActionSheet:(id)sender
{
UIActionSheet *showSheet = [[UIActionSheet alloc] initWithTitle:@"提示信息" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"确认" otherButtonTitles:nil];
[showSheet showInView:self.view];
[showSheet release];
}
- (IBAction)showAlertView:(id)sender
{
UIAlertView *alterView = [[UIAlertView alloc] initWithTitle:@"提示信息" message:@"啊啊" delegate:self cancelButtonTitle:@"取消" otherButtonTitles: nil];
[alterView show];
[alterView release];
}
UIActionSheet委托代码 ,当点击确认后,弹出UIAlertView窗口提示信息
- (void) actionSheet: (UIActionSheet *) actionSheet
didDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSString *msg = nil;
if (buttonIndex != [actionSheet cancelButtonIndex]) {
msg = [NSString stringWithString:@"你选择了确认"];
}else {
msg = [NSString stringWithString:@"你选择了取消"];
}
UIAlertView *alter = [[UIAlertView alloc] initWithTitle:@"提示信息" message:msg delegate:self cancelButtonTitle:@"取消" otherButtonTitles: nil];
[alter show];
[alter release];
[msg release];
}