简体   繁体   中英

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:

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM