Iphone之UIAlertView和UIActionSheet

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);
}




  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值