簡體   English   中英

Swift:無法同時滿足約束

[英]Swift: Unable to simultaneously satisfy constraints

一整天都在改變約束並試圖解決這個問題。 應用程序是一個簡單的問答游戲,加載良好,但每當我點擊一個按鈕時,它就會崩潰並給我這個錯誤。

Thread 1: signal SIGABRT

任何幫助是極大的贊賞。 這是日志所說的內容。

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

按鈕動作代碼

    @IBAction func AnswerButtonTapped(_ sender: UIButton) {

        HideDefault()
        UnHideAnswer()


    }


    @IBAction func NextButtonTapped(_ sender: UIButton) {

        RandomBreed()


        UnHideDefault()
        HideAnswer()

    }

您的格式在 @IBAction 函數上已關閉:

該函數的一般形式為:

addTarget(_:action:for:) 

所以你需要的是:

@IBAction func NextButtonTapped(_ sender: UIButton) {

    RandomBreed()


    UnHideDefault()
    HideAnswer()

}

此外,您需要刪除故事板中的舊連接,然后在更改功能后重新添加它。 它仍然會尋找舊的功能。 雖然名字看起來不錯。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM