【问题标题】:UIAlertView giving constraint errorsUIAlertView 给出约束错误
【发布时间】:2019-04-18 08:25:40
【问题描述】:

当我的应用程序出现问题时,我有以下代码来显示带有不同消息的警报。 该代码多年来一直运行良好,并且在我在 App Store 上的大多数应用程序中。

我正在制作一个新应用程序,只是添加了此代码,但是我在控制台中看到以下错误消息,我无法摆脱。

约束消息是指警报宽度,但我没有设置约束,也无法调整任何以使警告静音。

谁能告诉我出了什么问题。

谢谢

-(void)errorMessage:(id)sender
{

    UIAlertController *alert = [UIAlertController alertControllerWithTitle:NSLocalizedString(@"Information",)
                                                                   message:displaymessage
                                                            preferredStyle:UIAlertControllerStyleActionSheet];
    UIAlertAction *firstAction = [UIAlertAction actionWithTitle:NSLocalizedString(@"OK",)
                                                          style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {
                                                              [self dismissViewControllerAnimated:NO completion:nil];
                                                          }];

    [alert addAction:firstAction];
    [self presentViewController:alert animated:YES completion:nil];
}

2019-04-18 09:17:54.785207+0100 TestInputView5[1380:28232] [LayoutConstraints] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. 
    Try this: 
        (1) look at each constraint and try to figure out which you don't expect; 
        (2) find the code that added the unwanted constraint or constraints and fix it. 
(
    "<NSLayoutConstraint:0x600001e15b30 UIView:0x7fe60c6104e0.width == - 16   (active)>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x600001e15b30 UIView:0x7fe60c6104e0.width == - 16   (active)>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKitCore/UIView.h> may also be helpful.

【问题讨论】:

  • 您使用的是 Xcode 10.2 吗?在 iOS 12.2 上运行?我已经多次看到这一点......我认为这是一个内部约束冲突,因为它不会发生在 10.1 / 12.1 中(我目前没有要测试的 12.2 设备)。
  • 我正在使用最新的 Xcode 并更新了我的所有模拟器,并且在设备上使用 12.2 时也会出现此问题。
  • 我确实设法通过从操作表更改为警报来解决我的问题
  • 操作表仍然可以正常工作 - 你能看到我的代码有什么问题吗?
  • 有人可以帮忙吗,我们面临同样的问题

标签: autolayout uialertview nslayoutconstraint


【解决方案1】:

我在俄罗斯论坛上找到了解决方案。 它看起来像魔术,但它确实有效。 你需要做两件事: 1)向警报添加一个空视图 2) 不显示动画

alert.view.addSubview(UIView()) // I can't explain it, but it works!

self.present(alert, animated: false)

论坛致谢:https://quares.ru/?id=33972

帖子是机器翻译的,所以我想应该有英文原件(我找不到)

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2019-03-15
  • 2016-08-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-05-11
相关资源
最近更新 更多