UIAlertView
2015-09-03 15:08
387 查看
API:
#import <Foundation/Foundation.h>
#import <UIKit/UIKitDefines.h>
#import <UIKit/UITextField.h>
#import <UIKit/UIView.h>
typedef NS_ENUM(NSInteger, UIAlertViewStyle) {
UIAlertViewStyleDefault = 0,
UIAlertViewStyleSecureTextInput,
UIAlertViewStylePlainTextInput,
UIAlertViewStyleLoginAndPasswordInput
};
@protocol UIAlertViewDelegate; 遵守的协议
@class UILabel, UIToolbar, UITabBar, UIWindow, UIBarButtonItem, UIPopoverController;
NS_CLASS_AVAILABLE_IOS(2_0) @interface UIAlertView
: UIView
- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message
delegate:(id/*<UIAlertViewDelegate>*/)delegate cancelButtonTitle:(NSString *)cancelButtonTitle
otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATIONNS_EXTENSION_UNAVAILABLE_IOS("Use
UIAlertController instead.");
@property(nonatomic,assign) id /*<UIAlertViewDelegate>*/ delegate;
// weak reference
一般用于初始化的时候直接赋值
@property(nonatomic,copy) NSString *title;
@property(nonatomic,copy) NSString *message;
当一个view中有多个alertView时,用tag值区分
alert.tag=0
添加按钮并直接给标题
- (NSInteger)addButtonWithTitle:(NSString *)title;
指定索引的按钮标题
- (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex;
按钮总数
@property(nonatomic,readonly) NSInteger numberOfButtons;
取消按钮的索引值
@property(nonatomic) NSInteger cancelButtonIndex;
获取其他按钮的索引值
@property(nonatomic,readonly) NSInteger firstOtherButtonIndex;
@property(nonatomic,readonly,getter=isVisible) BOOL visible;
显示弹出的方法,不掉用,则不显示整个alertview控件
- (void)show;
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;
alert显示的样式,默认的样式为UIAlertViewStyleDefault(一共有4个样式,在上面typedef NS_ENUM)
@property(nonatomic,assign) UIAlertViewStyle alertViewStyle NS_AVAILABLE_IOS(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.
/ *检索文本字段索引,提高NSRangeException textFieldIndex时是禁止入内的。
在索引0将成为第一个文本字段(单一字段或登录字段),在指数1将密码字段。* / */
- (UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex NS_AVAILABLE_IOS(5_0);
@end
@protocol UIAlertViewDelegate <NSObject>
@optional
选中的那个button处理点击事件,传递的参数是button的索引值
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
- (void)alertViewCancel:(UIAlertView *)alertView; 取消按钮的事件
- (void)willPresentAlertView:(UIAlertView *)alertView; 即将显示时的事件
- (void)didPresentAlertView:(UIAlertView *)alertView; 已经显示时的事件
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex;
即将消失时执行的事件
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:
(NSInteger)buttonIndex; 已经消失时执行的事件
- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView;
@end
基于UITableView
//当选中某行,所触发的方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{
// 屏幕上弹出的提示框(可以不遵守UIAlertViewDelegate协议也能使用)
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"这是个UIAlertView"message:@"啦啦" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消",nil];
alert.tag=100;
[alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex==0) {
NSLog(@"点击的是第一个按钮");//可以任意写想要的事件
}
else if (buttonIndex==1){
NSLog(@"点击的是第二个按钮");
}
else if (buttonIndex==2){
NSLog(@"点击的是第三个按钮");
}
}
#import <Foundation/Foundation.h>
#import <UIKit/UIKitDefines.h>
#import <UIKit/UITextField.h>
#import <UIKit/UIView.h>
typedef NS_ENUM(NSInteger, UIAlertViewStyle) {
UIAlertViewStyleDefault = 0,
UIAlertViewStyleSecureTextInput,
UIAlertViewStylePlainTextInput,
UIAlertViewStyleLoginAndPasswordInput
};
@protocol UIAlertViewDelegate; 遵守的协议
@class UILabel, UIToolbar, UITabBar, UIWindow, UIBarButtonItem, UIPopoverController;
NS_CLASS_AVAILABLE_IOS(2_0) @interface UIAlertView
: UIView
- (instancetype)initWithTitle:(NSString *)title message:(NSString *)message
delegate:(id/*<UIAlertViewDelegate>*/)delegate cancelButtonTitle:(NSString *)cancelButtonTitle
otherButtonTitles:(NSString *)otherButtonTitles, ... NS_REQUIRES_NIL_TERMINATIONNS_EXTENSION_UNAVAILABLE_IOS("Use
UIAlertController instead.");
@property(nonatomic,assign) id /*<UIAlertViewDelegate>*/ delegate;
// weak reference
一般用于初始化的时候直接赋值
@property(nonatomic,copy) NSString *title;
@property(nonatomic,copy) NSString *message;
当一个view中有多个alertView时,用tag值区分
alert.tag=0
添加按钮并直接给标题
- (NSInteger)addButtonWithTitle:(NSString *)title;
指定索引的按钮标题
- (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex;
按钮总数
@property(nonatomic,readonly) NSInteger numberOfButtons;
取消按钮的索引值
@property(nonatomic) NSInteger cancelButtonIndex;
获取其他按钮的索引值
@property(nonatomic,readonly) NSInteger firstOtherButtonIndex;
@property(nonatomic,readonly,getter=isVisible) BOOL visible;
显示弹出的方法,不掉用,则不显示整个alertview控件
- (void)show;
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;
alert显示的样式,默认的样式为UIAlertViewStyleDefault(一共有4个样式,在上面typedef NS_ENUM)
@property(nonatomic,assign) UIAlertViewStyle alertViewStyle NS_AVAILABLE_IOS(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.
/ *检索文本字段索引,提高NSRangeException textFieldIndex时是禁止入内的。
在索引0将成为第一个文本字段(单一字段或登录字段),在指数1将密码字段。* / */
- (UITextField *)textFieldAtIndex:(NSInteger)textFieldIndex NS_AVAILABLE_IOS(5_0);
@end
@protocol UIAlertViewDelegate <NSObject>
@optional
选中的那个button处理点击事件,传递的参数是button的索引值
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
- (void)alertViewCancel:(UIAlertView *)alertView; 取消按钮的事件
- (void)willPresentAlertView:(UIAlertView *)alertView; 即将显示时的事件
- (void)didPresentAlertView:(UIAlertView *)alertView; 已经显示时的事件
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex;
即将消失时执行的事件
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:
(NSInteger)buttonIndex; 已经消失时执行的事件
- (BOOL)alertViewShouldEnableFirstOtherButton:(UIAlertView *)alertView;
@end
基于UITableView
//当选中某行,所触发的方法
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{
// 屏幕上弹出的提示框(可以不遵守UIAlertViewDelegate协议也能使用)
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"这是个UIAlertView"message:@"啦啦" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消",nil];
alert.tag=100;
[alert show];
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex==0) {
NSLog(@"点击的是第一个按钮");//可以任意写想要的事件
}
else if (buttonIndex==1){
NSLog(@"点击的是第二个按钮");
}
else if (buttonIndex==2){
NSLog(@"点击的是第三个按钮");
}
}
相关文章推荐
- ios开发 UI阶段第八周
- UINavigationController
- 区间离散化+线段树区间求最值poj 3368 Frequent values
- Drupal安装百度编辑器Ueditor for wysiwyg
- iOS软件开发之在UIScrollView上添加手势不能触发解决办法
- this class is not key value coding-compliant for the key progressVIew
- 1056. Mice and Rice (25)
- [翻译]Cell 中的视图控制器
- iPhone开发之UITableView的小试牛刀 利用MVC模式从plist文件读取数据并字典转模型的格式实现
- iPhone开发UI组件UIDatePickerView的预习
- iphone开发UI组件之UIDatePicker日期选择组件的预习
- UIColor的小技巧
- 奔跑在学习的道路上,有你,有他,有她,有大家(UIT)
- 开发中多条件搜索是使用StringBuilder创建sql语句
- Effective Java 英文 第二版 读书笔记 Item 2:Consider a builder when faced with many constructor parameters.
- Android UI设计——ViewPage中PagerTabStrip与PagerTitleStrip添加标题栏(三)
- Packet for query is too large
- UIDatePIcker
- UITableView表格拆分
- StringBuilder和String的区别