2016-11-24 206 views
-3

中有视图中的三个textFields,如下图所示在图像:应用程序崩溃为[的UITextField resignFirstResponder]

enter image description here

当我点击这些文本框的一个,一个textField可以becomeFirstResponder,则键盘出现了,没有崩溃。 当我点击'完成'或使这些文本框中的一个 resignFirstResponder时,键盘将消失。但当 键盘消失时,我的应用程序崩溃它。

错误:

iOS 8: [UICompatibilityInputViewController isKindOfClass:]: message sent to deallocated instance 0x7fd6b6074dd0

iOS 9: [UIInputWindowController parentViewController]: message sent to deallocated instance 0x7fde7c004400

iOS 10: [UICompatibilityInputViewController retain]...

+4

添加相关的代码,请 – Jens

+0

我们不知道什么UICompatibilityInputViewController和UIInputWindowController是。他们可以食用吗? –

+0

检查您的textFieldShouldReturn(_ :)方法在其中执行一些操作。 – Sommm

回答

0

使用此代码:

and also set the delegates of the text fields 

- (BOOL)textFieldShouldReturn:(UITextField *)theTextField { 
if (theTextField == yourTextFieldOne) { 
    [theTextField becomeFirstResponder]; 
} else if (theTextField == yourTextFieldTwo) { 
    [self.textPassword becomeFirstResponder]; 
}else if (theTextField == yourTextFieldThree) { 
    [theTextField resignFirstResponder]; 
} 
return YES; 
} 
+0

谢谢,我会试试看。我使用'IQKeyboardManager'框架,这没关系? –

+0

我试了一下,没有解决,谢谢你所有的时间。 –

+0

它会工作nt担心:) –

0
- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 
    [self setupBackBtn]; 
    // 初始化导航条 
    [self setupNav]; 
    //点击空白 收回键盘 
    UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(keyboardHide:)]; 
    tapGestureRecognizer.cancelsTouchesInView = NO; 
    [self.view addGestureRecognizer:tapGestureRecognizer]; 
    _confirmBtn.layer.cornerRadius = 5.f; 
} 
+0

删除轻拍手势方法并使用我的代码先生。可能会帮助你很多。 –

+0

我删除了水龙头手势方法并使用了你的代码。但是,它不工作。我的应用程序仍然崩溃。我发现了一个常规模式,如果我的视图需要文本框和键盘出现,当键盘消失时,我的应用程序将崩溃。所有拥有textfield.oh我的上帝的视图。错误是一样的。 –

0
// 设置导航条 
- (void)setupNav { 
    UILabel *titleLabel = [[UILabel alloc] init]; 
    titleLabel.text = @"忘记密码"; 
    titleLabel.textColor = HexColor(0x795033); 
    // titleLabel.font = HNLightFont(20.0); 
    titleLabel.font = [UIFont systemFontOfSize:20.0]; 
    [titleLabel sizeToFit]; 
    self.navigationItem.titleView = titleLabel; 

    // 这2句代码起到向下偏移64的作用 
    self.edgesForExtendedLayout = UIRectEdgeNone; 
    self.automaticallyAdjustsScrollViewInsets = NO; 
}