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

来源:互联网 发布:java finally 放return 编辑:程序博客网 时间:2024/05/27 20:26
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按钮文字为红色加粗字体



1 0
原创粉丝点击