UIAlertView、UIActionSheet

来源:互联网 发布:小米快传 mac 编辑:程序博客网 时间:2024/05/21 11:28

*初始化Action Sheet 和 Alert 并显示在屏幕上

(1)initWithTitle: 设置标题,将会显示在Alert 的顶部

UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle: @"Do you like 蓝鸥?" delegate: self cancelButtonTitle: @"Bye Bye" destrutiveButtonTitle: @"Yes, I like!" otherButtonTitles: @" ", nil];

[actionSheet showInView: self.view];

(2)Alert

UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"通知" message: @"涨工资了"

delegate: selfcancelButtonTitle: @"取消" otherButtonTitles: nil];

[alert show];


基本属性

1、创建Action Sheet需要多个参数

(1)initWithTitle: 设置标题,将会显示在Action Sheet 的顶部;

(2)delegate: 设置Action Sheet的一个按钮被按下后,它的delegagte将会被通知,并且这个delegate的actionSheet: didDismissWithButtonIndex方法将会执行。这里,我们将delegate设成self,这个可以保证执行我们自己在ViewController.m 写的 actionSheet: didDismissWithButtonIndex 方法。

(3)cancelButtonTitle: 设置取消按钮的标题,这个取消按钮将会显示在Action Sheet 的最下边。

(4)destructiveButtonTitle: 设置第一个确定按钮的标题,这个按钮可以理解成:“好的,继续”。

(5)otherButtonTitles: 可以设置任意多的确定按钮,想要添加两个按钮,可以写成:otherButtonTitles: @"New Button1", @"New Button2", nil

2、创建一个Alert 也要填写很多参数

(1)initWithTitle: 设置标题,将会显示在Alert 的顶部

(2)message: 设置提示消息内容

(3)delegate: 设置Alert 的委托,这里,我们设成self

(4)cancelButtonTitle: 设置取消按钮的标题

(5)otherButtonTitles: 与Action Sheet 类似

(6)[alert show]这条语句用来显示Alert

转自《蓝鸥科技iOS开发指南》

0 0
原创粉丝点击