【问题标题】:Constraint in code SIGABRT Error代码中的约束 SIGABRT 错误
【发布时间】:2017-01-19 14:47:24
【问题描述】:

[last]1 [last]2

我正在尝试向我的 repeatSegment 添加约束。

    //Repeat Segment
        repeatSegment?.setNeedsDisplay()

        repeatSegment?.translatesAutoresizingMaskIntoConstraints = false
        let repeatSegmentConstraint1 = NSLayoutConstraint(item: repeatSegment!, attribute: .width, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1.00, constant: 190) <<Error here

【问题讨论】:

  • 也许我错了(很有可能),但你可以使用self 作为toItem 中的值吗...不应该是self.view 还是只是view?我的意思是...self 在这种情况下是UIViewController
  • 你能再检查一下吗,我得到了新的错误
  • 不要在问题中发布代码截图。复制并粘贴代码本身。我无法阅读问题中的代码。与错误消息相同。复制并粘贴文本。
  • 我认为这会提供更多错误发生的原因。对不起
  • 我找到了这个答案:stackoverflow.com/a/14033030/4063602(基本上,将约束添加到超级视图,而不是子视图。在你的情况下,view 而不是songSlider

标签: swift sigabrt


【解决方案1】:

从上面的 cmets 可以看出,这里有两个问题。

  1. self 不能用作toItem 的参数。在这种情况下,self 是导致错误的UIViewController。为了解决这个问题,改用了view

  2. this answer 中可以看出,必须将约束添加到superView 而不是child,在这种情况下添加到view 而不是songSlider

    李>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-08
    • 1970-01-01
    • 2014-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多