【问题标题】:Xcode 'NSGenericException', reason: 'Unable to install constraint on viewXcode 'NSGenericException',原因:'无法在视图上安装约束
【发布时间】:2013-10-27 22:39:43
【问题描述】:

我在我的项目中遇到了这个异常,我不知道如何解决它。

Terminating app due to uncaught exception 'NSGenericException', reason: 'Unable to install constraint on view.  Does the constraint reference something from outside the subtree of the view?  That's illegal. constraint:<NSLayoutConstraint:0x1e583670 UIDatePicker:0x1f83c590.bottom == UIControl:0x1e582160.bottom> view:<UIControl: 0x1e582160; frame = (0 0; 320 504); autoresize = W+H; layer = <CALayer: 0x1e5822a0>>'

基本上,我的应用中有 2 个屏幕(视图控制器)。我为此使用了导航控制器。

在我的第一个屏幕中,我有两个 textfields、一个 UIDatePicker 和一个 UIButton,它们会将用户发送到下一个屏幕(视图)。当文本框被点击时,它会显示一个 UIDatePicker 而不是通常的键盘让用户输入日期

我通过在我的 viewDidLoad 方法中编写这段代码来做到这一点:

// Set the input way for the date textfields
[startDateTextField setInputView:datePicker];
[endDateTextField setInputView:datePicker];

这两个文本字段共享一个UIDatePicker(这并不重要,这是一个开始/结束日期的事情)。此外,在运行应用程序时,UIDatePicker 也会被隐藏。仅当文本框当前为firstResponder时才可见

当我点击文本字段,通过 UIDatePicker 输入日期,点击按钮转到下一个屏幕,然后点击返回按钮返回主屏幕后,就会发生异常。

但是当我点击按钮进入下一个屏幕而不点击文本字段并激活 UIDatePicker 时,我没有收到任何异常消息。所以这肯定是我如何使用 UIDatePicker 的问题?

我通过 xib 拖放创建了 UIDatePicker。我没有以编程方式创建它。

有人知道怎么解决吗?

【问题讨论】:

  • 你解决了吗?我对 DatePicer 和 TextField 有确切的问题。

标签: ios objective-c exception constraints uidatepicker


【解决方案1】:

尝试在点击下一步按钮时关闭日期选择器。使用 [self.view endEditing:YES];听起来日期选择器没有被正确清理。

【讨论】:

  • 感谢您的回复。我尝试了你的建议,但我仍然收到错误消息。我的 viewWillDisappear 方法中也有这一行
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多