线程1:由于Button,信号SIGABRT错误

时间:2018-11-26 20:52:47

标签: swift xcode

我仍在学习Swift和Xcode,因此请以外行的术语尽可能多地解释,以便我能够理解并尝试解决此问题,但我遇到了Sigbrt错误,但不确定为什么。香港专业教育学院创建了大量的按钮,并将其链接到我已经完成的viewcontroller.swift,但是对于我一生来说,我不明白为什么我得到这个错误。任何帮助将不胜感激。

首先是调试错误:

2018-11-26 20:30:42.713790+0000 Numbers[2058:130834] -[Numerology.twoViewController generateYourNumbersButtonPress:]: unrecognized selector sent to instance 0x7fac2973d5a0
2018-11-26 20:30:42.724547+0000 Numbers[2058:130834] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Numbers.twoViewController generateYourNumbersButtonPress:]: unrecognized selector sent to instance 0x7fac2973d5a0'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000107e6a1bb __exceptionPreprocess + 331
    1   libobjc.A.dylib                     0x0000000106448735 objc_exception_throw + 48
    2   CoreFoundation                      0x0000000107e88f44 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    3   UIKitCore                           0x000000010a823b4a -[UIResponder doesNotRecognizeSelector:] + 287
    4   CoreFoundation                      0x0000000107e6eed6 ___forwarding___ + 1446
    5   CoreFoundation                      0x0000000107e70da8 _CF_forwarding_prep_0 + 120
    6   UIKitCore                           0x000000010a7f6ecb -[UIApplication sendAction:to:from:forEvent:] + 83
    7   UIKitCore                           0x000000010a2320bd -[UIControl sendAction:to:forEvent:] + 67
    8   UIKitCore                           0x000000010a2323da -[UIControl _sendActionsForEvents:withEvent:] + 450
    9   UIKitCore                           0x000000010a23131e -[UIControl touchesEnded:withEvent:] + 583
    10  UIKitCore                           0x000000010a8320a4 -[UIWindow _sendTouchesForEvent:] + 2729
    11  UIKitCore                           0x000000010a8337a0 -[UIWindow sendEvent:] + 4080
    12  UIKitCore                           0x000000010a811394 -[UIApplication sendEvent:] + 352
    13  UIKitCore                           0x000000010a8e65a9 __dispatchPreprocessedEventFromEventQueue + 3054
    14  UIKitCore                           0x000000010a8e91cb __handleEventQueueInternal + 5948
    15  CoreFoundation                      0x0000000107dcf721 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    16  CoreFoundation                      0x0000000107dcef93 __CFRunLoopDoSources0 + 243
    17  CoreFoundation                      0x0000000107dc963f __CFRunLoopRun + 1263
    18  CoreFoundation                      0x0000000107dc8e11 CFRunLoopRunSpecific + 625
    19  GraphicsServices                    0x000000010ff861dd GSEventRunModal + 62
    20  UIKitCore                           0x000000010a7f581d UIApplicationMain + 140
    21  Numbers                          0x0000000105b17ed7 main + 71
    22  libdyld.dylib                       0x0000000109303575 start + 1
    23  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

下面是我的代码:

import UIKit

class twoViewController: UIViewController {
    let ballArray = ["brownBall1","brownBall2","bbrownBall3","brownBall4","brownball5","lightBlue6","lightBlue7","lightBlue8","lightBlue9","lightBlue10","yellowBall11","yellowBall12","yellowBall13","yellowBall14","yellowball15","silverBall16","silverBall17","silverBall18","silverBall19","silverBall20","redBall21","redBall22","redBall23","redBall24","redBall25","purpleBall26","purpleBall27","purpleBall28","purpleBall29","purpleBall30","greenBall31","greenball32","greenball33","greenball34","greenBall35","goldBall36","goldBall37","goldBall38","goldBall39","goldBall40","blueBall41","blueBall42","blueBall43","blueBall44","blueball45","blackBall46","blackBall47","blackBall48","blackBall49","blackBall50"]

    let luckyStarArray = ["goldOne", "goldTwo", "goldThree", "goldFour", "goldFive", "goldSix", "goldSeven", "goldEight", "goldBballNine"]

    @IBOutlet weak var starView1: UIImageView!
    @IBOutlet weak var starView2: UIImageView!
    @IBOutlet weak var starView3: UIImageView!
    @IBOutlet weak var starView4: UIImageView!
    @IBOutlet weak var starView5: UIImageView!

    @IBOutlet weak var luckyStar1: UIImageView!
    @IBOutlet weak var luckyStar2: UIImageView!

    override func viewDidLoad() {
        super.viewDidLoad()

        func generateYourNumbersButtonPress(_ sender: UIButton) {
            let shuffledBallArray = ballArray.shuffled()

            starView1.image = UIImage(named: shuffledBallArray[0])
            starView2.image = UIImage(named: shuffledBallArray[1])
            starView3.image = UIImage(named: shuffledBallArray[2])
            starView4.image = UIImage(named: shuffledBallArray[3])
            starView5.image = UIImage(named: shuffledBallArray[4])

            let shuffledLuckyBallArray = luckyStarArray.shuffled()

            luckyStar1.image = UIImage(named: shuffledLuckyBallArray[0])
            luckyStar2.image = UIImage(named: shuffledLuckyBallArray[1])
        }
    }
}

1 个答案:

答案 0 :(得分:0)

首先,不要将generateYourNumbersButtonPress放在viewDidLoad内。

第二,将generateYourNumbersButtonPress标记为@IBAction

第三,解决上述两个问题后,将操作重新连接到按钮,以便将正确的操作方法连接到按钮的事件。