IOS使用视图控制器和视图(一)显示提示 UIAlertView
来源:互联网 发布:淘宝的伴侣 一个桃子 编辑:程序博客网 时间:2024/06/05 11:16
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Title"message:@"Message"delegate:nilcancelButtonTitle:@"Cancel"otherButtonTitles:@"Ok", nil];[alertView show];PS:需要创建更多按键在otherButton中添加,以nil结尾。
需要知道被按下哪一个键
首先在视图控制器头文件中添加委托:
@interface Displaying_Alerts_with_UIAlertViewViewController: UIViewController <UIAlertViewDelegate>@end创建UIAlertView时delegate置为self。
在实现文件中添加按键响应函数
- (void) alertView:(UIAlertView *)alertViewclickedButtonAtIndex:(NSInteger)buttonIndex{NSString *buttonTitle = [alertView buttonTitleAtIndex:buttonIndex];if ([buttonTitle isEqualToString:[self yesButtonTitle]]){NSLog(@"User pressed the Yes button.");}else if ([buttonTitle isEqualToString: [self noButtonTitle]]){NSLog(@"User pressed the No button.");}}该函数传入的是被按下的按键的索引buttonIndex,[alertView buttonTitleAtIndex:buttonIndex]获得的是被按下按键的标题。
需要输入一些信息则修改样式
typedef enum {UIAlertViewStyleDefault = 0,//默认样式UIAlertViewStyleSecureTextInput,//密码输入样式UIAlertViewStylePlainTextInput,//一个简单输入框样式UIAlertViewStyleLoginAndPasswordInput//账号密码输入样式} UIAlertViewStyle;
- (void) viewDidAppear:(BOOL)animated{[super viewDidAppear:animated];UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Credit Card Number"message:@"Please enter your credit card number:"delegate:selfcancelButtonTitle:@"Cancel"otherButtonTitles:@"Ok", nil];[alertView setAlertViewStyle:UIAlertViewStylePlainTextInput];/* Display a numerical keypad for this text field */UITextField *textField = [alertView textFieldAtIndex:0];//获得输入的信息textField.keyboardType = UIKeyboardTypeNumberPad; //输入键盘样式[alertView show];}上面代码效果如下:
0 0
- IOS使用视图控制器和视图(一)显示提示 UIAlertView
- IOS使用视图控制器和视图(六)使用 UIActivityViewController 显示分享选项
- IOS使用视图控制器和视图(九) UITextField属性
- IOS使用视图控制器和视图(二)通过 UISwitch 创建及使用开关
- IOS使用视图控制器和视图(三)通过 使用 UIPickerView 来选择数据
- IOS使用视图控制器和视图(四)使用UISlider 实现指定范围值的选择
- IOS使用视图控制器和视图(五)使用 UISegmentedControl 做简单选项分组
- IOS使用视图控制器和视图(七) NavigationController 的使用(基于storyboard)
- [IOS]使用视图控制器和视图(十)使用 UIWebView 加载 Web 页面
- IOS开发之视图和视图控制器
- IOS使用视图控制器和视图(八)Label 标签的属性
- 视图和视图控制器
- 视图和视图控制器
- 视图和视图控制器
- 视图和视图控制器
- iOS获取当前正在显示的窗口、视图控制器、视图
- IOS UITableView表视图和导航控制器的交互使用
- 【IOS学习】IOS开发之视图和视图控制器
- 银行知识普及
- 说点什么有求的看电视苏打粉
- mac机之间创建本地svn服务器
- 查select-1搜到的,分享给大家
- 根深蒂固的个风格
- IOS使用视图控制器和视图(一)显示提示 UIAlertView
- 十大滤波算法程序
- Fatal error: Call to undefined function apc_fetch() in /var/www/lib/cakephp-2.1.1/lib/Cake/Cache/Eng
- Android 中的接口回调
- ASCII码表
- C#开发——窗体去边框之后无法移动解决办法
- 【人文】第一部分对保不住秘密的人,要保持距离
- pthreads 安装error: pthreads requires ZTS,please re-compile PHP with ZTS enabled
- 将文字显示在图片上面,并使文字背景半透明