gpt4 book ai didi

iphone - 我无法在第二个UITextField 中输入~~ 谁能教教我?

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:21:11 24 4
gpt4 key购买 nike

我做了一个 UIViewController。这是一个登录窗口。我使用 presentModalViewController 方法来弹出这个登录窗口。在此登录窗口的 View 中,我放置了两个带有简单代码的 UITextField、一个用户名文本字段和一个密码文本字段。但是当我运行这个应用程序时,出现了一个错误。我点击一个可选的文本框,它可以随意输入。然后,我点击另一个文本字段,我无法再输入任何内容。

UITextField * f1 = [[UITextField alloc] initWithFrame:CGRectMake(100, 150, 100, 25)];
[f1 setBorderStyle:UITextBorderStyleRoundedRect];
UITextField * f2 = [[UITextField alloc] initWithFrame:CGRectMake(100, 180, 100, 25)];
[f2 setBorderStyle:UITextBorderStyleRoundedRect];

[[self view] addSubview:f1];
[[self view] addSubview:f2];

有人遇到过这种情况吗?请帮助我,谢谢大家。

最佳答案

给字段一个委托(delegate)连接

[f1 setDelegate:self];

在你的.h文件中坑

@interface SomeViewController : UIViewController<UITextFieldDelegate>
{
}
-(IBAction)textFieldDone:(id)sender;
@end

对于字段:

-(void)viewDidLoad{
UITextField * f1 = [[UITextField alloc]initWithFrame:CGRectMake(10, 170.0, 300, 25)];
f1.borderStyle = UITextBorderStyleRoundedRect;
f1.text = @"";
[f1 setDelegate:self];
[f1 addTarget:self action:@selector(textFieldDone:)
forControlEvents:UIControlEventEditingDidEndOnExit];
[self.view addSubview:ke ti kazam zosto na telefon];

UITextField * f2 = [[UITextField alloc]initWithFrame:CGRectMake(10, 210, 300, 25)];
f2.borderStyle = UITextBorderStyleRoundedRect;
f2.text = @"";
[f2 setDelegate:self];
[f2 addTarget:self action:@selector(textFieldDone:)
forControlEvents:UIControlEventEditingDidEndOnExit];
[self.view addSubview:f2];
}
-(IBAction)textFieldDone:(id)sender{
NSLog(@"textFieldDone");
}

希望对你有帮助。

关于iphone - 我无法在第二个UITextField 中输入~~ 谁能教教我?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11324856/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com