Swift 2 - Sigabrt错误

时间:2015-11-15 18:04:14

标签: ios swift unrecognized-selector

我为游戏创建倒数计时器,但我收到了SIGABRT错误。我在Swift 2编码。它从45秒倒计时,然后有两个其他标签,一个减少5秒,另一个减少10秒。该应用程序在模拟器中成功打开。一旦我点击屏幕,它就会崩溃。我尝试删除Storyboard上的按钮/标签与ViewController.swift之间的所有联系。然后,我重新"附加"他们。按钮没有文字,高于一切。因此,无论您点击屏幕的哪个位置,它都会启动或重置。单击按钮后,NSTimer将启动。再次单击该按钮后,它将重置计时器,以便下次准备好。

ViewController代码:

//
//  ViewController.swift
//  CS:GO C4 Timer
//
//  Created by Panja on 11/14/15.
//  Copyright © 2015 Panja. All rights reserved.
//

import UIKit


class ViewController: UIViewController {

    var Main:Int = 0
    var Kit:Int = 0
    var NoKit:Int = 0

    @IBOutlet weak var MainTime: UILabel!

    @IBOutlet weak var DiffuseKit: UILabel!

    @IBOutlet weak var NoDiffuseKit: UILabel!

    var TimerCount = 0;
    var TimerRunning = false;
    var Timer = NSTimer();

    var Toggle = false;

    func Countdown(){
        //Time Left Before Bomb Explodes
        TimerCount = 45;
        TimerCount -= 1
        if(TimerCount <= 0){
            MainTime.text = "No Time"
        }else{
            MainTime.text = "\(TimerCount)"
            Main = TimerCount
        }
        //Time Left To Diffuse With A Kit
        Kit = Main - 5
        if(Kit <= 0){
            DiffuseKit.text = "No Time"
        }else{
            DiffuseKit.text = "\(Kit)"
        }
        //Time Left To Diffuse Without A Kit
        NoKit = Main - 10
        if(NoKit <= 0){
            NoDiffuseKit.text = "No Time"
        }else{
            NoDiffuseKit.text = "\(NoKit)"
        }
    }

    @IBAction func ToggleButton(sender: AnyObject) {
        //If The Button Is At Its Default at 45 Seconds & Not Running
        if(Toggle == false){
            if TimerRunning == false{
                Timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("Counting"), userInfo: nil, repeats: true)
                TimerRunning = true;
                Toggle = true;
            }
        //If Timer is Running & Needs To Be Stopped
        }else if (Toggle == true){
            if TimerRunning == true{
                Timer.invalidate()
                TimerRunning = false
                TimerCount = 45;
                MainTime.text = "45"
                Toggle = false;
            }
        }
    }



    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

调试控制台出错:

2015-11-15 12:20:54.288 CS:GO C4 Timer[32688:6460757] -[CS_GO_C4_Timer.ViewController Counting]: unrecognized selector sent to instance 0x7f866bf19d00
2015-11-15 12:20:54.323 CS:GO C4 Timer[32688:6460757] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CS_GO_C4_Timer.ViewController Counting]: unrecognized selector sent to instance 0x7f866bf19d00'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001080849b5 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000109c83deb objc_exception_throw + 48
    2   CoreFoundation                      0x000000010808cfdd -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x0000000107fda9fa ___forwarding___ + 970
    4   CoreFoundation                      0x0000000107fda5a8 _CF_forwarding_prep_0 + 120
    5   Foundation                          0x000000010846b6f1 __NSFireTimer + 83
    6   CoreFoundation                      0x0000000107fe4de4 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
    7   CoreFoundation                      0x0000000107fe4991 __CFRunLoopDoTimer + 1089
    8   CoreFoundation                      0x0000000107fa6331 __CFRunLoopRun + 1937
    9   CoreFoundation                      0x0000000107fa5918 CFRunLoopRunSpecific + 488
    10  GraphicsServices                    0x000000010c5ccad2 GSEventRunModal + 161
    11  UIKit                               0x00000001088a199e UIApplicationMain + 171
    12  CS:GO C4 Timer                      0x0000000107ea218d main + 109
    13  libdyld.dylib                       0x000000010a7de92d start + 1
    14  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Main.Storyboard Image of The Main Storyboard

线程1 - 12主要 Picture of the Thread 1 file that shows when the application crashes

1 个答案:

答案 0 :(得分:1)

问题在于CountingCountdown是两个不同的词。