动态 UITextfield 不响应键盘输入

发布于 2024-10-08 06:20:01 字数 1426 浏览 1 评论 0原文

您好,下面是我正在使用的代码,文本字段是在 .h 文件中创建的,当我运行代码时,文本字段不会响应键盘(没有键入的字母可见),而且当我在键盘上单击“完成”时,它不会触发文本字段应该返回方法。请帮忙!!!

UIActionSheet *aac =[[UIActionSheet alloc] initWithTitle:@"New list item" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
UIDatePicker *theDatePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0.0,100.0,0.0,0.0)];
self.textField=[[UITextField alloc] init];
self.textField.frame = CGRectMake(12, 45, 260, 25);
[self.textField setDelegate:self];
self.textField.textColor=[UIColor blackColor];
self.textField.backgroundColor=[UIColor whiteColor];

[textField setBorderStyle:UITextBorderStyleRoundedRect];
[textField setReturnKeyType:UIReturnKeyDone];
textField.keyboardType=UIKeyboardAppearanceDefault;

[aac addSubview:textField];
[aac addSubview:theDatePicker];

[textField release];
[theDatePicker release];

UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Done"]];
closeButton.momentary=YES;
closeButton.frame = CGRectMake(270, 7.0f, 50.0f, 30.0f);
closeButton.segmentedControlStyle=UISegmentedControlStyleBar;
closeButton.tintColor =[UIColor blackColor];
[closeButton addTarget:self action:@selector(dismissActionSheet) forControlEvents:UIControlEventValueChanged];
[aac addSubview:closeButton];
[closeButton release];
[aac showInView:self.view];
[aac setBounds:CGRectMake(0, 0, 320, 685)];

HI all below is the code i am using, the textField is created in .h file and when i run the code the text field doesnt respond to keyboard( no letters typed are visible) also when i click Done on keybpard it does not trigger textfieldshouldreturn method. please help!!!

UIActionSheet *aac =[[UIActionSheet alloc] initWithTitle:@"New list item" delegate:self cancelButtonTitle:nil destructiveButtonTitle:nil otherButtonTitles:nil];
UIDatePicker *theDatePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0.0,100.0,0.0,0.0)];
self.textField=[[UITextField alloc] init];
self.textField.frame = CGRectMake(12, 45, 260, 25);
[self.textField setDelegate:self];
self.textField.textColor=[UIColor blackColor];
self.textField.backgroundColor=[UIColor whiteColor];

[textField setBorderStyle:UITextBorderStyleRoundedRect];
[textField setReturnKeyType:UIReturnKeyDone];
textField.keyboardType=UIKeyboardAppearanceDefault;

[aac addSubview:textField];
[aac addSubview:theDatePicker];

[textField release];
[theDatePicker release];

UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Done"]];
closeButton.momentary=YES;
closeButton.frame = CGRectMake(270, 7.0f, 50.0f, 30.0f);
closeButton.segmentedControlStyle=UISegmentedControlStyleBar;
closeButton.tintColor =[UIColor blackColor];
[closeButton addTarget:self action:@selector(dismissActionSheet) forControlEvents:UIControlEventValueChanged];
[aac addSubview:closeButton];
[closeButton release];
[aac showInView:self.view];
[aac setBounds:CGRectMake(0, 0, 320, 685)];

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风向决定发型 2024-10-15 06:20:01

您是否尝试过从 textField 之前删除 self. ?如果您在标头中定义了它,并在 .m 中使用了 @property 和 @synthesize,那么您应该没问题。另外,请确保界面中有

Have you tried removing the self. from before textField? If you have defined it in your header, as well as used @property, and @synthesize in your .m, you should be good. Also, make sure you have the <UITextFieldDelegate> in your interface.

魂归处 2024-10-15 06:20:01

我刚刚遇到了同样的问题;当我触摸我的文本字段时,它确实会调出键盘,但是当点击键盘时,文本字段中没有出现字母。

就我而言,我一直在弄乱 AppDelegate.m 并删除了 [self.window makeKeyAndVisible];。因此,再次将其放回去(在应用程序中:didFinishLaunchingWithOptions:)为我解决了这个问题。

I just had the same problem; My textfield did bring up the keyboard when I touched it, but no letters appeared in the textfield when tapping on the keyboard.

In my case I had been messing with the AppDelegate.m and removed the [self.window makeKeyAndVisible];. So putting it back again (in application:didFinishLaunchingWithOptions:) solved it for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文