动态UITextfield不响应键盘输入

时间:2010-12-20 06:28:50

标签: iphone keyboard uitextfield

以下是我正在使用的代码,textField是在.h文件中创建的,当我运行代码时,文本字段对键盘没有响应(没有键入的字母是可见的)当我单击在键盘上完成时它也会不触发textfieldshouldreturn方法。请帮忙!!!

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)];

2 个答案:

答案 0 :(得分:0)

您是否尝试过删除textField之前的self.?如果你已经在标题中定义了它,并在.m中使用了@property和@synthesize,那么你应该很好。另外,请确保您的界面中有<UITextFieldDelegate>

答案 1 :(得分:0)

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

在我的情况下,我一直在弄乱AppDelegate.m并删除了[self.window makeKeyAndVisible];。所以再把它放回去(在应用程序中:didFinishLaunchingWithOptions :)解决了它。