ios 关于UIAlertView与UIActionSheet的区别,以及在使用过程中注意事项

UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"hello" 
                     message:@"I'm Apple"
                              delegate:self 
                             cancelButtonTitle:@"ok" 
                        otherButtonTitles:nil];
[alert show];
[alert release];
复制代码

有多个按钮的时候

UIAlertView *alert =[[UIAlertView alloc] initWithTitle:@"hello" 
                     message:@"O哈啊"
                              delegate:self 
                             cancelButtonTitle:@"ok" 
                        otherButtonTitles:@"cancel",@"Ignore",nil ];

UIAlertViewDelegate 中的 

 - (void) alertView:(UIAlertView *)alertview

clickedButtonAtIndex:(NSInteger)buttonIndex 

方法可以知道你点的是那个按钮。


UIActionSheet是从屏幕底部弹起的一个模态对话框,它的使用也很简单
复制代码
UIActionSheet *actionSheet = [[UIActionSheet alloc]
        initWithTitle:@"Are you sure?"
        delegate:self
        cancelButtonTitle:@"No Way!"
        destructiveButtonTitle:@"Yes, I'm sure!"
        otherButtonTitles:nil];
    [actionSheet showInView:self.view];

  
  
  1. (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex  代理方法,知道你点击了那个按钮
复制代码

注意:在iphone和ipad上使用UIActionShee控件t的效果会不一样,在苹果的官方文档中有相关说明:

在ipad上使用UIActionSheet控件改控件不再从底部弹出,而是从屏幕中间弹出与UIAlertView警告框弹出有点类似。效果如图所示,cancelButton按钮文字显示不出来,destructiveButtonTitle按钮文字为红色加粗字体



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值