您的位置:首页 > 产品设计 > UI/UE

Iphone之UIAlertView和UIActionSheet

2012-03-12 16:35 302 查看
UIAlertView和UIActionSheet的用法很简单,直接看代码:

1.UIAlertView:

.h头文件:

#import <UIKit/UIKit.h>

@interface DialogControl : UIViewController<UIAlertViewDelegate> {//注意要实现这个协议
UIAlertView *alertView1;//多个dialog的点击事件需要区分是哪一个dialog
UIAlertView * al;
}
-(IBAction) showDialog;
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;//重写点击事件方法
@end


.m文件中的方法:

//点击界面上的一个button促发的方法
-(IBAction)showDialog{
alertView1 = [[UIAlertView alloc]initWithTitle:@"提示" message:@"注意增加一个确定按钮的点击事件" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
[alertView1 show];

//[alertView release];
}
//重写协议中对话筐按钮点击事件方法
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

if (alertView == alertView1) {
if (buttonIndex == 1) {
al = [[UIAlertView alloc]initWithTitle:@"提示" message:@"你按下了确定按钮" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
[al show];
}
}
else if(alertView == al){
if (buttonIndex == 0) {
NSLog(@"你点击了确定按钮");
}
}

}
2.UIActionSheet:

.h头文件:

#import <UIKit/UIKit.h>

@interface OtherView : UIViewController<UIActionSheetDelegate> {//注意实现这个协议

}

@end
.m文件的方法:

//进入页面就调用的方法,进入页面就弹出
-(void) viewDidAppear:(BOOL)animated{
UIActionSheet *actionSeet = [[UIActionSheet alloc]initWithTitle:@"选择事件" delegate:self cancelButtonTitle:nil destructiveButtonTitle:@"destructivebutton" otherButtonTitles:@"one",@"two",@"three", nil];
[actionSeet showInView:self.view];
[actionSeet release];
}

//重写协议中actionsheet中按钮点击方法
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@"%d",buttonIndex);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: