iphone开发 UIActionSheet(操作表) 和UIAlertView(警告)的用法
来源:互联网 发布:同轴电缆传输网络结构 编辑:程序博客网 时间:2024/04/30 09:41
一.UIActionSheet(操作表) 和UIAlertView(警告)
UIActionSheet用于迫使用户在两个或更多的选项之间进行选择的模式视图。操作表从屏幕底部弹出,显示一系列按钮供用户选择,用户只有单击一个按钮后才能继续使用应用程序。
UIAlertView警告以蓝色圆角矩形形式出现在屏幕中部,警报可显示一个或多个按钮
为了让控制器类充当操作表的委托,控制器需要遵从UIActionSheetDelegate协议
二.UIActionSheet(操作表)的创建
initWithTitle:delegate:cancelButtonTitle:destructiveButtonTitle:otherButtonTitles:
注释:initWithTitle是对象函数
initWithTitle:操作表标题
delegate:接收对象
cancelButtonTitle关闭按钮标题
destructiveButtonTitle: 操作按钮标题
otherButtonTitles:其他按钮
1. 创建一个简单的操作表:
//open a dialog with an OK and cancel button
UIActionSheet*actionSheet = [[UIActionSheet alloc]
initWithTitle:@" UIActionSheet<title>"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"OK"
otherButtonTitles:nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheetshowInView:self.view]; //show from our table view (pops up in the middle of the table)
[actionSheetrelease];
2. 创建两个按钮的操作表
// open a dialog with an OKand cancel button
UIActionSheet*actionSheet = [[UIActionSheet alloc]
initWithTitle:@" UIActionSheet<title>"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"OK"
otherButtonTitles:nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
[actionSheetshowInView:self.view]; //show from our table view (pops up in the middle of the table)
[actionSheetrelease];
3. 创建自定义操作表:
//open a dialog with two custom buttons
UIActionSheet*actionSheet = [[UIActionSheet alloc]
initWithTitle:@" UIActionSheet<title>"
delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:@"Button1", @"Button2", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleDefault;
actionSheet.destructiveButtonIndex = 1; // make the second button red(destructive)
[actionSheetshowInView:self.view]; //show from our table view (pops up in the middle of the table)
[actionSheet release];
对操作表中按钮的操作用UIActionSheetDelegate协议函数,这里你可以控制在点击按钮之后的操作
#pragma mark - UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet*)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
//the user clicked one of the OK/Cancel buttons
if(buttonIndex == 0)
{
//NSLog(@"ok");
}
else
{
//NSLog(@"cancel");
}
}
三.UIAlertView(警告)的创建
initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:
注释:initWithTitle是对象函数
initWithTitle:警告框标题
message:警告内容
delegate:接收对象
cancelButtonTitle:关闭按钮标题
otherButtonTitles:其他按钮
1. 创建一个简单的警告框
//open an alert with just an OK button
UIAlertView*alert = [[UIAlertView alloc]
initWithTitle:@"UIAlertView"
message:@"<Alertmessage>"
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles: nil];
[alert show];//显示警告框
[alert release];//释放警告框
2. 创建两个按钮的警告框
// open a alert with an OK andcancel button
UIAlertView*alert = [[UIAlertView alloc]
initWithTitle:@"UIAlertView"
message:@"<Alertmessage>"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil];
[alert show];//显示警告框
[alert release];//释放警告框
3. 创建自定义警告框
//open an alert with two custom buttons
UIAlertView*alert = [[UIAlertView alloc]
initWithTitle:@"UIAlertView"
message:@"<Alertmessage>"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Button1",@"Button2", nil];
[alert show];//显示警告框
[alert release];//释放警告框
4 警告框中按钮的操作
对警告框中按钮的操作用UIAlertViewDelegate协议函数,这里你可以控制在点击按钮之后的操作
#pragma mark - UIAlertViewDelegate
- (void)alertView:(UIAlertView*)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
//use "buttonIndex" to decide your action
//
}
5 给警告框添加子视图:
UIAlertView*alert = [[UIAlertView alloc] initWithTitle:@"UIAlertView " message:nil delegate:nil
cancelButtonTitle:nil otherButtonTitles:nil];
[alert show];
UIActivityIndicatorView*activeView = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
activeView.center = CGPointMake(alert.bounds.size.width/2.0f,alert.bounds.size.height-40.0f);
[activeView startAnimating];
[alert addSubview:activeView];
[activeView release];
[alert release];
- iphone开发 UIActionSheet(操作表) 和UIAlertView(警告)的用法
- Swift UIAlertView(警告视图)、UIActionSheet(操作表)
- iOS开发 对话框UIActionSheet和UIAlertView用法
- iOS开发 对话框UIActionSheet和UIAlertView用法
- IOS学习笔记(九)之UIAlertView(警告视图)和UIActionSheet(操作表视图)基本概念和使用方法
- 介绍UIALertView和UIActionSheet的用法。
- iOS UIAlertView和UIActionSheet的用法
- 介绍UIALertView和UIActionSheet的用法。
- 介绍UIALertView和UIActionSheet的用法。
- iOS9中UIAlertView和UIActionSheet的用法
- UI控件篇——UIActionSheet(操作表)和UIAlertView(警告框)
- UI控件篇——UIActionSheet(操作表)和UIAlertView(警告框)
- Iphone之UIAlertView和UIActionSheet
- IPHONE应用开发 - 开发常用控件:UIActionSheet和UIAlertView学习
- IPHONE应用开发 - 开发常用控件:UIActionSheet和UIAlertView学习
- 【UIAlertView警报和UIActionSheet操作表】
- 160,警告框UIAlertView和UIActionSheet
- iOS8 UIAlertView 和 UIActionSheet 的新用法 UIAlertController详解
- CSDN乐知李伟老师第二课
- Ubuntu11.10 64Bit版上的Android 4.0 开发环境搭建
- 对session和cookie的一些理解
- 如何从 wchar_t * 转换为其他字符串类型
- mysql中大小写敏感么?
- iphone开发 UIActionSheet(操作表) 和UIAlertView(警告)的用法
- Apache2 虚拟主机配置的例子
- java反射机制
- Oracle使用序列和触发器实现自增ID
- 性能测试的过程模型
- IT学习
- MySQL在MacOS上的安装记录
- 通过js控制节点显隐
- 如何加强开发部门与运营部门的协同工作 - TechExcel DevOps 解决方案