UIAlertView上怎么获取UITextField的内容
1个回答
推荐于2016-08-13 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517190
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
首先创建一个UIAlertView并且在上面添加一个UITextField
在UIAlertView上添加一个UITextField
Objective-C
UIAlertView *pwdAlert = [[UIAlertView alloc] initWithTitle:message
message:@"\n\n"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"确定", nil];
[pwdAlert setTag:kAlertTagOfJoinForumPassword];
[pwdAlert setDelegate:self];
UITextField *textFieldPwd = [[UITextField alloc] initWithFrame:CGRectMake(27.0, 60.0, 230.0, 25.0)];
[textFieldPwd setBackgroundColor:[UIColor whiteColor]];
[textFieldPwd setTag:kTextFieldTagOfForumPassword];
[textFieldPwd setPlaceholder:@"请输入密码"];
[pwdAlert addSubview:textFieldPwd;
[textFieldPwd release];
[pwdAlert show];
[pwdAlert release];
接下来获取UITextField里面输入的值,这里首先要实现UIAlertView的delegate的方法:alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
Objective-C
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSInteger aTag = [alertView tag];
//输入的密码
if(aTag == kAlertTagOfJoinForumPassword){
if (buttonIndex == 1) {
//选择确定
UITextField *pwdTextField = (UITextField *)[alertView viewWithTag:kTextFieldTagOfForumPassword];
NSString *pwd = [pwdTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
// .....
}else{
//选择取消
}
}
}
Categorized under: iphone/ipad, UIAlertView.
Tagged with: UIAlertView, UITextField, 输入.
Comments are closed.
在UIAlertView上添加一个UITextField
Objective-C
UIAlertView *pwdAlert = [[UIAlertView alloc] initWithTitle:message
message:@"\n\n"
delegate:self
cancelButtonTitle:@"取消"
otherButtonTitles:@"确定", nil];
[pwdAlert setTag:kAlertTagOfJoinForumPassword];
[pwdAlert setDelegate:self];
UITextField *textFieldPwd = [[UITextField alloc] initWithFrame:CGRectMake(27.0, 60.0, 230.0, 25.0)];
[textFieldPwd setBackgroundColor:[UIColor whiteColor]];
[textFieldPwd setTag:kTextFieldTagOfForumPassword];
[textFieldPwd setPlaceholder:@"请输入密码"];
[pwdAlert addSubview:textFieldPwd;
[textFieldPwd release];
[pwdAlert show];
[pwdAlert release];
接下来获取UITextField里面输入的值,这里首先要实现UIAlertView的delegate的方法:alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
Objective-C
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
NSInteger aTag = [alertView tag];
//输入的密码
if(aTag == kAlertTagOfJoinForumPassword){
if (buttonIndex == 1) {
//选择确定
UITextField *pwdTextField = (UITextField *)[alertView viewWithTag:kTextFieldTagOfForumPassword];
NSString *pwd = [pwdTextField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
// .....
}else{
//选择取消
}
}
}
Categorized under: iphone/ipad, UIAlertView.
Tagged with: UIAlertView, UITextField, 输入.
Comments are closed.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询