0

我已经添加了 myUITextFieldUITextViewinside ,UIWindow我无法在其中输入它们。两者都不允许我输入这些字段。而且,在键盘上按下返回时无法关闭它。

-(void)showAlert 
{
alertWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
alertView = [[UIView alloc] initWithFrame:CGRectMake(10, 115, 300, 230)];
alertWindow.windowLevel = UIWindowLevelAlert; // puts it above the status bar
alertView.center = CGPointMake(alertWindow.frame.size.width/2, alertWindow.frame.size.height/2);
alertView.backgroundColor = [UIColor whiteColor];
alertView.layer.borderWidth = 1.0;
alertView.layer.borderColor = [[UIColor whiteColor]CGColor];

UITextField *txt = ....
....
....
txt.delegate = self;
...
...
[alertView addSubview:txt];

UITextView *txtview = ...
....
....
txtview.delegate = self;
...
[alertView addSubview:txtview];

[alertWindow addSubview:alertView];
[alertWindow addSubviewWithZoomInAnimation:alertView duration:1.0 option:curveValues[0]];
[alertWindow setHidden:NO];
}

我也声明了这两个委托方法。我在那里放置了一个断点并进行了检查,即使该方法尚未调用。

更新 -

textFieldShouldReturn委托方法

- (BOOL) textFieldShouldReturn:(UITextField *)textField
{
    [textField resignFirstResponder];
    [reserveView resignFirstResponder];
    [reserveWindow resignFirstResponder];
    [self.reserveWindow endEditing:YES];
    [reserveView endEditing:YES];
    return YES;
}
4

5 回答 5

1

你应该试试这个从 UIWindow 关闭键盘

[self.window endEditing:YES];

来源

于 2013-03-04T06:05:05.347 回答
1

我发现,由于没有调用该方法,UIWindow因此,我将我的更改UIWindowUIView并且,我通过使用UIView+Animation.hfrom here解决了这个问题它提供了我所需要的动画。

- (void) addSubviewWithZoomInAnimation:(UIView*)view duration:(float)secs option:(UIViewAnimationOptions)option;
- (void) removeWithZoomOutAnimation:(float)secs option:(UIViewAnimationOptions)option;

感谢谷歌!干杯!

于 2013-03-06T05:56:27.657 回答
0

键盘永远不会自行关闭(即使您按回车键!)。您会注意到,在您的委托方法中,每当您按下返回/完成/等时,您都会收到事件。

每次有人按回车键时让键盘消失的一种简单方法是实现该- (BOOL)textViewShouldEndEditing:(UITextView *)textView方法。

- (BOOL)textViewShouldEndEditing:(UITextView *)textView
{
    [textView endEditing:YES];
    return YES;
}

编辑:在您的帖子中,您编辑说您已经声明了两个委托方法......有两个以上,所以您能澄清一下您实现了哪些方法吗?http://developer.apple.com/library/ios/#documentation/uikit/reference/UITextViewDelegate_Protocol/Reference/UITextViewDelegate.html#//apple_ref/occ/intf/UITextViewDelegate

于 2013-03-04T06:01:31.120 回答
0

试试这个

- (void)viewDidLoad
{
  [super viewDidLoad];
  UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
  tapGesture.cancelsTouchesInView = NO;
  [self.window addGestureRecognizer:tapGesture];
  //[self.view addGestureRecognizer:tapGesture];
  [tapGesture release];
}
-(void)dismissKeyboard
{
[txt resignFirstResponder];
[textView resignFirstResponder];
}
于 2013-03-04T06:26:57.987 回答
0

试试这个

这是文本字段的委托方法:-

  • (BOOL)textFieldShouldReturn:(UITextField *)textField

    {

    [txtview resignFirstResponder];
    

    返回否;

    }

于 2013-03-04T07:03:34.393 回答