Ios 自动布局约束在生产中引发异常

Ios 自动布局约束在生产中引发异常,ios,swift,autolayout,Ios,Swift,Autolayout,我遇到了一个非常奇怪的问题,我似乎不知道如何开始工作。当我在我的设备或模拟器上调试我的应用程序时,我没有得到任何错误。当我为临时部署构建它时,应用程序抛出异常并失败。我在日志中看到的错误是 [NSISEngine tryToAddConstraintWithMarker:expression:integralizationAdjustment:mutuallyExclusiveConstraints:] 我的布局在所有视图中都是这样的 我的约束将视图拉伸到屏幕的全宽,我正在BaseViewC

我遇到了一个非常奇怪的问题,我似乎不知道如何开始工作。当我在我的设备或模拟器上调试我的应用程序时,我没有得到任何错误。当我为临时部署构建它时,应用程序抛出异常并失败。我在日志中看到的错误是

[NSISEngine tryToAddConstraintWithMarker:expression:integralizationAdjustment:mutuallyExclusiveConstraints:]
我的布局在所有视图中都是这样的

我的约束将视图拉伸到屏幕的全宽,我正在BaseViewController中的视图上创建一个动态宽度约束,该约束将被所有其他视图继承。我已经为每个子视图创建了scrollView和contentView的委托

class BaseViewController: UIViewController, UITextFieldDelegate {
var activeField:UITextField?

@IBOutlet weak var scrollView: UIScrollView?
@IBOutlet weak var contentView: UIView?

override func viewDidLoad() {
    if(self.scrollView != nil)
    {
        // Do any additional setup after loading the view.
        let leftConstraint:NSLayoutConstraint = NSLayoutConstraint(item: self.contentView!, attribute: NSLayoutAttribute.Leading, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Left, multiplier: 1.0, constant: 0)

        self.view.addConstraint(leftConstraint)

        let rightConstraint:NSLayoutConstraint = NSLayoutConstraint(item: self.contentView!, attribute: NSLayoutAttribute.Trailing, relatedBy: NSLayoutRelation.Equal, toItem: self.view, attribute: NSLayoutAttribute.Right, multiplier: 1.0, constant: 0)

        self.view.addConstraint(rightConstraint)
    }

    super.viewDidLoad()
}
我非常乐意提供任何额外的信息,请尽管问,我会尽我所能给你

编辑

这仅在存档和运行时发生,且未连接到调试器。如果我调试一个发布版本,就没有问题

import UIKit

class BaseViewController: UIViewController, UITextFieldDelegate {
var activeField:UITextField?

@IBOutlet weak var scrollView: UIScrollView!

override func viewDidLoad() {

    super.viewDidLoad()
}



override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
    self.view.endEditing(true);
}

func textFieldShouldReturn(field: UITextField) -> Bool
{
    field.resignFirstResponder()

    return true
}

func textFieldDidBeginEditing(sender: UITextField)
{
    self.activeField = sender
}

func textFieldDidEndEditing(sender: UITextField)
{
    self.activeField = nil
}

func keyboardDidShow(notification: NSNotification)
{
    if(self.activeField != nil && self.scrollView != nil) {
        if let keyboardSize = (notification.userInfo?[UIKeyboardFrameBeginUserInfoKey] as? NSValue)?.CGRectValue() {
            let contentInsets = UIEdgeInsets(top: 0, left: 0, bottom: keyboardSize.height, right: 0)

            self.scrollView!.contentInset = contentInsets
            self.scrollView!.scrollIndicatorInsets = contentInsets

            var aRect = self.view.frame
            aRect.size.height -= keyboardSize.size.height

            if(!CGRectContainsPoint(aRect, self.activeField!.frame.origin)) {
                self.scrollView!.scrollRectToVisible(self.activeField!.frame, animated: true)
            }
        }            
    }
}

func keyboardWillBeHidden(notification: NSNotification)
{
    if(self.scrollView != nil) {
        let contentInsets:UIEdgeInsets = UIEdgeInsetsZero

        self.scrollView!.contentInset = contentInsets
        self.scrollView!.scrollIndicatorInsets = contentInsets
    }
}
}

我解决了我的问题。出于某种原因,我与您之间存在依赖关系问题或生成问题。我的ViewController继承了我的BaseViewController


由于某种原因,其中一个方法没有像预期的那样返回,它把一切都搞砸了。

两个约束相互矛盾,因此您可能会面临这样的问题

对于以编程方式添加约束的视图,是否已将TranslatesAutoReshizingMaskConstraints设置为否?我目前没有。我需要在父视图、滚动视图或我的内容视图上设置吗?
Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed: 
0   libsystem_c.dylib               0x0000000193c19690 __sfvwrite + 0
1   libsystem_c.dylib               0x0000000193c20958 __vfprintf + 11352
2   libsystem_c.dylib               0x0000000193c3b67c __v2printf + 584
3   libsystem_c.dylib               0x0000000193bce208 _vsnprintf + 300
4   libsystem_c.dylib               0x0000000193bcec54 snprintf_l + 20
5   CoreFoundation                  0x0000000181cc7018 __CFStringAppendFormatCore + 11580
6   CoreFoundation                  0x0000000181cc42a0 _CFStringCreateWithFormatAndArgumentsAux2 + 244
7   Foundation                      0x0000000182b0a444 -[NSPlaceholderString initWithFormat:locale:arguments:] + 168
8   Foundation                      0x0000000182b0a304 +[NSString stringWithFormat:] + 72
9   yazda-ios                       0x00000001000fcea0 +[NRMAThreadLocalStore currentThreadDictionary] (NRMAThreadLocalStore.m:238)
10  yazda-ios                       0x00000001000fb678 +[NRMAThreadLocalStore threadLocalTrace] (NRMAThreadLocalStore.m:36)
11  yazda-ios                       0x00000001000fc040 +[NRMAThreadLocalStore prepareSameThread:child:withParent:] (NRMAThreadLocalStore.m:126)
12  yazda-ios                       0x00000001000fbac0 +[NRMAThreadLocalStore pushChild:forParent:] (NRMAThreadLocalStore.m:91)
13  yazda-ios                       0x00000001000c92d4 +[NRMATraceController newTraceSetup:parentTrace:] (NRMATraceController.m:310)
14  yazda-ios                       0x00000001000c97d8 +[NRMATraceController enterMethod:fromObject:parentTrace:traceCategory:withTimer:] (NRMATraceController.m:374)
15  yazda-ios                       0x00000001000c95ac +[NRMATraceController enterMethod:fromObject:parentTrace:traceCategory:] (NRMATraceController.m:338)
16  yazda-ios                       0x00000001000b4498 NRMA__beginMethod (NRMAMethodProfiler.m:1051)
17  yazda-ios                       0x00000001000b406c NRMA__voidParamHandler (NRMAMethodProfiler.m:705)
18  yazda-ios                       0x0000000100047f38 yazda_ios.BaseViewController.viewDidLoad (yazda_ios.BaseViewController)() -> () (BaseViewController.swift:32)
19  yazda-ios                       0x00000001000b407c NRMA__voidParamHandler (NRMAMethodProfiler.m:707)
20  yazda-ios                       0x0000000100047f38 yazda_ios.BaseViewController.viewDidLoad (yazda_ios.BaseViewController)() -> () (BaseViewController.swift:32)