ios textfield输入的值怎么获取到

 我来答
打伞鱼Aw
2016-04-12 · TA获得超过7266个赞
知道大有可为答主
回答量:7524
采纳率:90%
帮助的人:1588万
展开全部
我给你一段我很久以前写的小demo,你就明白了,是把textField套在alertView里的
@interface ViewController : UIViewController <UIAlertViewDelegate, UITextFieldDelegate>{
UILabel *la;
UITextField *myTextField;
}

@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];

la = [[UILabel alloc] init];
la.Frame = CGRectMake(10, 150,300,30);
la.backgroundColor = [UIColor clearColor];
la.font = [UIFont fontWithName:@"Helvetica-Bold" size:20];
la.text = @"initLabel";
la.textAlignment = UITextAlignmentCenter;
la.shadowColor = [UIColor colorWithWhite:0.0f alpha:0.75f];
la.shadowOffset = CGSizeMake(0.0f, 5.0f);

la.textColor = [UIColor greenColor];

[self.view addSubview:la];

UIButton *alartBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
alartBtn.frame = CGRectMake(110, 50, 50, 50);
alartBtn.backgroundColor = [UIColor clearColor];
[alartBtn setTitle:@"alart" forState:UIControlStateNormal];
[alartBtn addTarget:self action:@selector(alartShow:) forControlEvents:UIControlEventTouchUpInside];
[alartBtn setAlpha:1.0];
[self.view addSubview:alartBtn];

}
-(void)alartShow:(id)sender{

UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Title" message:@" " delegate:self cancelButtonTitle:@"cancel" otherButtonTitles:@"OK", nil];
[alert show];
[alert release];

myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];

[myTextField setBackgroundColor:[UIColor whiteColor]];
[alert addSubview:myTextField];
[myTextField setDelegate:self];

[myTextField addTarget:self action:@selector(onTextFieldChanged:forEvent:) forControlEvents:UIControlEventEditingChanged];

NSLog(@"myTextField.text:%@", myTextField.text);

}

- (void)alertView: (UIAlertView *)alert clickedButtonAtIndex:(NSInteger)buttonIndex {
{

NSLog(@"%@", myTextField.text);
la.text = myTextField.text;

}
}

- (void)alertView:(UIAlertView *)alert didDismissWithButtonIndex:(NSInteger)buttonIndex{
if (buttonIndex == [alert cancelButtonIndex]) {
close(0);
}

}

- (void) onTextFieldChanged:(id)sender forEvent:(UIEvent *)event{

NSLog(@"%@", myTextField.text);
}

摘出来的,大概意思应该已经有了,你自己看一下吧
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式