[英]Swift: Unable to simultaneously satisfy constraints
Been changing around constraints and trying to figure this out all day.一整天都在改变约束并试图解决这个问题。 App is a simple quiz game, loads up fine, but whenever I tap a button it crashes and gives me this error.应用程序是一个简单的问答游戏,加载良好,但每当我点击一个按钮时,它就会崩溃并给我这个错误。
Thread 1: signal SIGABRT
Any help is greatly appreciated.任何帮助是极大的赞赏。 Here is what the log says.这是日志所说的内容。
2020-03-23 15:53:15.392269-0700 Name That Breed[49590:3684921] [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.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x6000013a1a40 h=--& v=--& UILabel:0x7f975c608da0'What type of dog is this?'.minX == - 113 (active, names: '|':UIView:0x7f975c60a230 )>",
"<NSAutoresizingMaskLayoutConstraint:0x6000013a0410 h=--& v=--& UILabel:0x7f975c608da0'What type of dog is this?'.width == 638 (active)>",
"<NSLayoutConstraint:0x6000013a27b0 UIView:0x7f975c60a230.centerX == UILabel:0x7f975c608da0'What type of dog is this?'.centerX (active)>",
"<NSLayoutConstraint:0x6000013a3700 'UIView-Encapsulated-Layout-Width' UIView:0x7f975c60a230.width == 414 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000013a27b0 UIView:0x7f975c60a230.centerX == UILabel:0x7f975c608da0'What type of dog is this?'.centerX (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.
2020-03-23 15:53:15.393351-0700 Name That Breed[49590:3684921] [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.
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x6000013a2e40 h=--& v=--& UIImageView:0x7f975c6091c0.minX == 49 (active, names: '|':UIView:0x7f975c60a230 )>",
"<NSAutoresizingMaskLayoutConstraint:0x6000013a21c0 h=--& v=--& UIImageView:0x7f975c6091c0.width == 314 (active)>",
"<NSLayoutConstraint:0x6000013a2800 UIView:0x7f975c60a230.centerX == UIImageView:0x7f975c6091c0.centerX (active)>",
"<NSLayoutConstraint:0x6000013a3700 'UIView-Encapsulated-Layout-Width' UIView:0x7f975c60a230.width == 414 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x6000013a2800 UIView:0x7f975c60a230.centerX == UIImageView:0x7f975c6091c0.centerX (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.
2020-03-23 15:53:17.996383-0700 Name That Breed[49590:3684921] -[Name_That_Breed.ViewController NextButtonTappedWithSender:]: unrecognized selector sent to instance 0x7f975c504480
2020-03-23 15:53:18.001322-0700 Name That Breed[49590:3684921] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Name_That_Breed.ViewController NextButtonTappedWithSender:]: unrecognized selector sent to instance 0x7f975c504480'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff23baa1ee __exceptionPreprocess + 350
1 libobjc.A.dylib 0x00007fff50864b20 objc_exception_throw + 48
2 CoreFoundation 0x00007fff23bcb154 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 UIKitCore 0x00007fff475a6e79 -[UIResponder doesNotRecognizeSelector:] + 302
4 CoreFoundation 0x00007fff23baef6c ___forwarding___ + 1436
5 CoreFoundation 0x00007fff23bb10f8 _CF_forwarding_prep_0 + 120
6 UIKitCore 0x00007fff4757a082 -[UIApplication sendAction:to:from:forEvent:] + 83
7 UIKitCore 0x00007fff46f608e5 -[UIControl sendAction:to:forEvent:] + 223
8 UIKitCore 0x00007fff46f60c2f -[UIControl _sendActionsForEvents:withEvent:] + 398
9 UIKitCore 0x00007fff46f5fb8e -[UIControl touchesEnded:withEvent:] + 481
10 UIKitCore 0x00007fff475b4a31 -[UIWindow _sendTouchesForEvent:] + 2604
11 UIKitCore 0x00007fff475b6338 -[UIWindow sendEvent:] + 4596
12 UIKitCore 0x00007fff47591693 -[UIApplication sendEvent:] + 356
13 UIKitCore 0x00007fff47611e5a __dispatchPreprocessedEventFromEventQueue + 6847
14 UIKitCore 0x00007fff47614920 __handleEventQueueInternal + 5980
15 CoreFoundation 0x00007fff23b0d271 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
16 CoreFoundation 0x00007fff23b0d19c __CFRunLoopDoSource0 + 76
17 CoreFoundation 0x00007fff23b0c974 __CFRunLoopDoSources0 + 180
18 CoreFoundation 0x00007fff23b0767f __CFRunLoopRun + 1263
19 CoreFoundation 0x00007fff23b06e66 CFRunLoopRunSpecific + 438
20 GraphicsServices 0x00007fff38346bb0 GSEventRunModal + 65
21 UIKitCore 0x00007fff47578dd0 UIApplicationMain + 1621
22 Name That Breed 0x000000010ba58b5b main + 75
23 libdyld.dylib 0x00007fff516ecd29 start + 1
24 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Code for button action按钮动作代码
@IBAction func AnswerButtonTapped(_ sender: UIButton) {
HideDefault()
UnHideAnswer()
}
@IBAction func NextButtonTapped(_ sender: UIButton) {
RandomBreed()
UnHideDefault()
HideAnswer()
}
Your format is off on the @IBAction function:您的格式在 @IBAction 函数上已关闭:
The general form of the function is:该函数的一般形式为:
addTarget(_:action:for:)
So what you need is:所以你需要的是:
@IBAction func NextButtonTapped(_ sender: UIButton) {
RandomBreed()
UnHideDefault()
HideAnswer()
}
Also, you need to delete the old connection in the storyboard then re-add it after you make the function change.此外,您需要删除故事板中的旧连接,然后在更改功能后重新添加它。 It will still be looking for the old function.它仍然会寻找旧的功能。 Even though the name looks right.虽然名字看起来不错。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.