UIAlertView----警告视图

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

UIAlertView是一个简单的类,它的作用就是对弹出的警告框进行设置

一、首先给大家看一下它的形成代码和效果图

1、将tableView中的cell属性进行一下简单的设置:

在- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;//返回每个单元格中显示内容的View

将cell的accessoryType属性设为UITableViewCellAccessoryDetailDisclosureButton或者是UITableViewCellAccessoryDetailButton

e.g. cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton ;

2、//点击触发的方法

-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath

{

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"你点击了辅助按钮" delegate:nil cancelButtonTitle:@"不好" otherButtonTitles:@"好", nil];

alert.alertViewStyle = UIAlertViewStyleDefault ;//默认模式

[alert show];

}

3、效果图

是不是感觉很熟悉,下面这个效果见到的时候也很多。

从上面可以看到实现它的代码不是很多,主要的还是熟悉它们的属性以及方法,这样就可以展示出我们想要的结果

二、属性以及方法

1、属性

@PRoperty(nonatomic,assign) id /*<UIAlertViewDelegate>*/ delegate; 代理属性

@property(nonatomic,copy) NSString *title; //警告的名字(显示在第一行的东东)

@property(nonatomic,copy) NSString *message; //警告信息(显示在第二行的东东)

@property(nonatomic,readonly) NSInteger numberOfButtons; //按钮的个数

@property(nonatomic) NSInteger cancelButtonIndex; //删除哪一个按钮

@property(nonatomic,readonly) NSInteger firstOtherButtonIndex; //

@property(nonatomic,readonly,getter=isVisible) BOOL visible; //是否可用

@property(nonatomic,assign)UIAlertViewStylealertViewStyle //警告视图格式

UIAlertViewStyle有四种格式: (上面的第二张图就是由它改变而来的,大家试下其他的属性)

UIAlertViewStyleDefault //默认的格式,没有添加其他东西

UIAlertViewStyleSecureTextInput, //出现一个textField供用户输入

UIAlertViewStylePlainTextInput, //出现一个textField供用户输入

UIAlertViewStyleLoginAndPassWordInput //密码登陆模式,需要输入用户名和密码

2、初始化方法

- (id)initWithTitle:(NSString *)title message:(NSString *)message delegate:(id /*<UIAlertViewDelegate>*/)delegate cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitles:(NSString *)otherButtonTitles, ...

3、添加按钮 —从中间由右向左添加

- (NSInteger)addButtonWithTitle:(NSString *)title; // returns index of button. 0 based.

- (NSString *)buttonTitleAtIndex:(NSInteger)buttonIndex;

4、显示警告 —要想出现警告提示就一定要有这个方法

- (void)show;

5、移除按钮

- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated;

上面用到了UIAlertViewDelegate这个代理方法,这里就不介绍了。

如有错误,欢迎批评指正,谢谢。

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航