我遇到了一个非常奇怪的问题,我似乎无法弄清楚如何开始工作。当我在我的设备或模拟器上调试我的应用程序时,我没有收到任何错误。当我为临时部署构建它时,应用程序抛出异常并失败。我在日志中收到的错误是
[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
}
}
}
我的日志现在看起来像这样,我不确定我的问题是什么。
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)
答案 0 :(得分:0)
我想出了我的问题。出于某种原因,我有一个依赖问题或构建问题,我的ViewController继承了我的BaseViewController。
出于某种原因,其中一种方法并没有像预期的那样返回,而且它将一切都搞砸了。
答案 1 :(得分:0)
两个约束彼此矛盾,所以你可能面临这样的