iOS界面编程-UIAlertView
来源:互联网 发布:mac修改安全设置 编辑:程序博客网 时间:2024/06/07 23:28
一、介绍
UIAlertView这个视图控件在iOS8以后不再使用转而使用UIAlertController,UIAlertView主要用给用户显示警告信息,提示用户注意。UIAlertView跟action sheet类似,主要在外表上有所区别。
二、相关属性及方法
初始化alert view
- (instancetype nonnull)initWithTitle:(NSString * nullable)titlemessage:(NSString * nullable)message
delegate:(id nullable)delegate
cancelButtonTitle:(NSString * nullable)cancelButtonTitle
otherButtonTitles:(NSString * nullable)otherButtonTitles,
@property(nonatomic,weak)iddelegate
@property(nonatomic,copy)NSString *title
@property(nonatomic,copy)NSString *message;
增加一个按钮和其文字,并返回其增加的序列,按钮按照其增加的先后进行排序,按钮不能被自定义。
- (NSInteger)addButtonWithTitle:(NSString *)title; // returns index of button. 0 based.
- (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex; 返回某个序列中按钮的文字。
@property(nonatomic,readonly)NSInteger numberOfButtons; 返回按钮的个数。
@property(nonatomic)NSInteger cancelButtonIndex; // if the delegate does not implement -alertViewCancel:, we pretend this button was clicked on. default is -1
@property(nonatomic,readonly)NSInteger firstOtherButtonIndex;// -1 if no otherButtonTitles or initWithTitle:... not used
@property(nonatomic,readonly,getter=isVisible)BOOL visible;
- (void)show;
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;
// alert显示给用户的类型,iOS5以后可以用。默认UIAlertViewStyleDefault
@property(nonatomic,assign)UIAlertViewStyle alertViewStyle__OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);
/* Retrieve a text field at an index - raises NSRangeException when textFieldIndex is out-of-bounds.
The field at index 0 will be the first text field (the single field or the login field), the field at index 1 will be the password field. */
- (UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex__OSX_AVAILABLE_STARTING(__MAC_NA,
三使用例子
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"提示" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"登录", nil]; alertView.title =@"用户登录"; alertView.alertViewStyle = UIAlertViewStyleLoginAndPasswordInput; [alertView show];
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ NSString *titleButon= [alertView buttonTitleAtIndex:buttonIndex]; if ([titleButon isEqualToString:@"登录"]) { NSString *userName= [alertView textFieldAtIndex:0].text; NSString *password= [alertView textFieldAtIndex:1].text; NSLog(@"userName=%@,password=%@",userName,password); }}
控制台输出:
2015-10-09 09:47:19.280 Xcode_learn[1317:50099] userName=tyyt,password=hhhh
- iOS界面编程-UIAlertView
- iOS开发-UIAlertView
- iOS界面编程-UILabel
- iOS界面编程-UIImageView
- iOS界面编程-UIPickerView
- iOS界面编程-UIProgressView
- iOS界面编程-UIActivityIndicatorView
- iOS界面编程-UIWebView
- iOS界面编程-UIButton
- iOS界面编程-UITextField
- iOS界面编程-UIDatePicker
- iOS界面编程-UIPageControl
- Swift开发IOS-UIAlertView
- IOS手动编写界面----UIAlertView的详细使用示例
- IOS-65-解决UIAlertView导致界面弹出键盘的问题
- IOS UIAlertView
- iOS UIAlertView
- ios UIAlertView
- 如何在一台电脑上开启多个tomcat
- 星级设置
- 【第6周 项目2 - 建立链栈算法库】
- How to Spot a Good IT Developer
- 第四周项目2--建立“单链表”算法库
- iOS界面编程-UIAlertView
- 第六周项目1--建立顺序栈算法库
- Developer Productivity: Skilled Versus Average
- 第四周项目3---单链表的应用之连接
- 将秒转换成时分秒
- 【bzoj2480】Mod 扩展大步小步
- Size Matters
- 第四周项目三-单链表的应用(3)
- hdu1272小希的迷宫【并查集基础】