iphone - 我无法在第二个UITextField中输入~~有人可以教我吗?

标签 iphone objective-c ios xcode ipad

我制作了一个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/

相关文章:

iphone - _kCTSuperscriptAttributeName 编译错误

ios - 如何对工作日的NSArray进行排序?

ios - 如何在应用程序被杀死时从服务器推送通知

ios - 如何创建可以从任何方法访问的 UIImage 属性?

objective-c - iPad 标题栏。导航栏还是工具栏?

ios - 黑色条纹显示在旧项目的 View 中

ios - 多人失物招领处

ios - 确定用户是否可以看到按钮

ios - 如果 app delegate 想快速使用主 Storyboard文件,它必须实现 window 属性

javascript - 取消事务时在后续 storekit.init 上出现多个 "Cannot connect to iTunes store"消息 -Cordova/Phonegap