·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> app软件开发 >> IOS开发 >> UIAlertView&UIActionSheet随笔笔记

UIAlertView&UIActionSheet随笔笔记

作者:佚名      IOS开发编辑:admin      更新时间:2022-07-23

系统UIAlertView在很多地方有使用到,其创建的初始化的方法为:

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

其中title、message 如上图所示;delegate是设置监听对象,通常设为self,也就是ViewController控制器为监听者,并遵循UIAlertViewDelegate协议,可使用协议中的clickedButtonAtIndex设置当点击了按钮后的实现内容;cancelButtonTitle为图中的“取消”,otherButtonTitle为图中的“确定”,按钮可以添加多个,所以...后还可以继续追加;

 

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;

通过传入的buttonIndex获得用户点击的是哪个button;

通过alertViewStyle的类型可以设置文本框样式;

通过textFieldAtIndex:(NSInteger)textFieldIndex获得具体是哪个UITextField;

最后通过show方法显示UIAlertView;

 

UIActionSheet于UIAlertView类似,第一项按钮为红色提示,显示方法不是show而是 showInView.