UIAlertView上添加输入框UITextField
2015-11-10 18:18
549 查看
UIAlertView上添加输入框UITextField
1、初始化UIAlertView,并添加UITextField
UIAlertView *exitAlertView=[[UIAlertView alloc]initWithTitle:@"退出原因" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
exitAlertView.alertViewStyle=UIAlertViewStylePlainTextInput;
UITextField *reasonField=[exitAlertView textFieldAtIndex:0];
reasonField.placeholder=@"请输入退出原因";
[exitAlertView show];
2、在UIAlertView的代理方法中为确定按钮添加点击事件(前提记得添加UIAlertViewDelegate)
#pragma mark - UIAlertViewDelegate
//为按钮添加点击事件
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@" button index=%ld is clicked.....", buttonIndex);
UITextField *reasonField = [alertView textFieldAtIndex:0];
//_reasonStr 为全局变量的Nsstring,获取UITextField中的输入值
_reasonStr=reasonField.text;
//buttonIndex为1是确定按钮
if (buttonIndex == 1) {
//调用接口
[self postQuitTravel];
[reasonField resignFirstResponder];
}
else{
[reasonField resignFirstResponder];
}
}
1、初始化UIAlertView,并添加UITextField
UIAlertView *exitAlertView=[[UIAlertView alloc]initWithTitle:@"退出原因" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
exitAlertView.alertViewStyle=UIAlertViewStylePlainTextInput;
UITextField *reasonField=[exitAlertView textFieldAtIndex:0];
reasonField.placeholder=@"请输入退出原因";
[exitAlertView show];
2、在UIAlertView的代理方法中为确定按钮添加点击事件(前提记得添加UIAlertViewDelegate)
#pragma mark - UIAlertViewDelegate
//为按钮添加点击事件
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
NSLog(@" button index=%ld is clicked.....", buttonIndex);
UITextField *reasonField = [alertView textFieldAtIndex:0];
//_reasonStr 为全局变量的Nsstring,获取UITextField中的输入值
_reasonStr=reasonField.text;
//buttonIndex为1是确定按钮
if (buttonIndex == 1) {
//调用接口
[self postQuitTravel];
[reasonField resignFirstResponder];
}
else{
[reasonField resignFirstResponder];
}
}
相关文章推荐
- UGUI - 长按事件实现
- iOS 9界面适配利器:详解Xcode 7的新特性UIStackView
- LCS(Longest Common Subsequence 最长公共子序列)
- 77.下拉刷新MJRefresh和UITableView的section headerView冲突的原因分析与解决方案
- Android 腾讯入门教程( 智能手表UI设计 和 MVC模式 )
- Android开发UI之响应系统UI变化
- leetcode 303: Range Sum Query - Immutable
- iOS摄像头和相册-UIImagePickerController-浅析
- Queue
- iOS 开发之UIAlertController
- 关于getparameter()取不到值的问题和jbuilder安装问题
- UIButton中内容大小,以及UITextFiled改变和选中
- iOS UIDataDetectorType 详解
- 微软的COM中GUID和UUID、CLSID、IID .
- 多个ViewController 只隐藏一个ViewController的UINavigationBar 和UITabBar
- UILabel和UIButton
- UITextView解析
- hdu 1423 Greatest Common Increasing Subsequence(最长公共递增子序列LICS)
- Android开发UI之隐藏导航栏
- Android stduio依赖关系