UIAlertView的一些使用
来源:互联网 发布:2016淘宝客还能赚钱吗 编辑:程序博客网 时间:2024/05/15 03:07
一些关于UIALertView的使用,在开发一些小项目中,对于一些提示语,一些输入框,通常都是直接使用native的alertView即可。而且,UIAlertView除了本身自带几种格式外,还可以放置多种控件,包括pickupView、UItextView、UITextField等,例如要实现像微博的多行文本输入,并显示当前输入数字的功能
//-(void)addInfo { //对成员变量初始化 _textView = [[UITextView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height)]; _textView.delegate = self; //获取曾填写过的数据(有一个发送请求可返回上次填写的方法,在此不予显示) NSString *lastInfo = *********; if (lastInfo != 0) { _textView.text = lastInfo; } //创建一个alertView _alertView = [[UIAlertView alloc]initWithTitle:@"请填写备注" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil]; //将文本框添加到alertView上(注意ios7之后不可直接用addSubiew的方法了 if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) { [_alertView setValue:_textView forKey:@"accessoryView"]; }else{ [_alertView addSubview:_textView]; } //显示alertView [_alertView show] }//#pragma mark - AlertViewDelegate-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{ switch (buttonIndex) { case 1:{//确定 NSString *lastInfo = *********; NSString *newText = _textView.text; if (newText.length == 0) {//内部的提示方法 [****** ******:@"你还未填写备注"]; return; } else if([newText isEqualToString:sellerMemo]) { [****** ******:@"你还未做任何更改"]; return; }else{ [self changeInfo:newText]; } } break; default: break; }}//当textView在编辑时会调用改方法- (void)textViewDidChange:(UITextView *)textView { NSInteger number = [_textView.text length]; //设置一个提示输入字数的标签,frame根据各自需求设置 UILabel *statusLabel = [[UILabel alloc] initWithFrame:CGRectMake(*,*,*,*)]; statusLabel.font = [UIFont systemFontOfSize:9]; statusLabel.textAlignment = NSTextAlignmentLeft; statusLabel.backgroundColor = [UIColor whiteColor]; //140减去当前已输入的数,显示还可以输入的数量 statusLabel.text = [NSString stringWithFormat:@"%ld",(140-(long)number)]; //添加到textView上 [_textView addSubview:statusLabel];}//对于超出字数限制时,也可在这里做处理-(void)textViewDidEndEditing:(UITextView *)textView{}/** * 添加备注 */- (void)changeInfo:(NSString *)info { NSInteger number = [_textView.text length]; if (number > 200) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"请不要超过200个字" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil]; [alert show]; } //将其存起来,当结束回到controller时会立即刷新发送更改数据的请求给服务器,即可实现修改 @"内部变量" = info; [****** ******:@"备注添加成功"];}
0 0
- UIAlertView的一些使用
- UIAlertView的使用
- UIAlertView的使用
- UIAlertView的使用
- UIAlertView,UIActionSheet的使用
- UIAlertView 的使用
- UIALertView的使用
- UIAlertView的使用
- UIAlertView的使用
- UIAlertView 的使用
- UIAlertView的使用
- UIAlertView的使用
- UIAlertView的使用介绍
- UIAlertView的快捷使用
- UIAlertView的使用的小结
- 多个UIAlertView的使用
- 多个UIAlertView的使用
- UIAlertController 和 UIAlertView的使用
- 职工管理系统——动态数组实现
- 之前写的检测mysql 从服务器延迟的脚本
- jvm优化
- (4.1.28.1)HTTP通信之HttpClinet保持登录状态问题
- 压缩文件最基本原理——map实现
- UIAlertView的一些使用
- android ftp多线程多任务下载时的listview滑动列表错乱解决方法
- 模拟Listener对button的监听过程
- jvm优化检测多线程竞争
- #第二周1000题解#
- 最大连续子段和、M子段和
- 年轻的时候需要更加的奋斗!
- Android FlowLayout
- (4.1.28.3)第二种方法HttpClient.setCookieStore(mCookieStore)实现的HTTP工具类