Swift:无法同时满足约束条件

问题描述 投票:0回答:2

编辑:已解决-函数格式错误,需要在修复后将其重新链接到按钮。

更改约束并试图整日解决这个问题。应用程序是一个简单的测验游戏,可以很好地加载,但是每当我点击一个按钮时,它就会崩溃并显示此错误。

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()

    }

ios swift xcode constraints
2个回答
0
投票

您的格式在@IBAction函数上处于关闭状态:

该函数的一般形式是:

addTarget(_:action:for:) 

所以您需要的是:

@IBAction func NextButtonTapped(_ sender: UIButton) {

    RandomBreed()


    UnHideDefault()
    HideAnswer()

}

-1
投票

它不是因为约束而崩溃,而是因为找不到附加的选择器而崩溃。您可以共享一些代码来在按钮和动作之间建立联系吗?

© www.soinside.com 2019 - 2024. All rights reserved.