2015-11-15 77 views
-4

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

的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

+4

*阅读*错误信息!你用'Selector(“Counting”)创建定时器,但是你的代码中没有'Counting'方法。也许你的意思是(扰流板被删除)? –

+2

额外downvote后改变问题,以便答案似乎没有帮助了。如果你的问题解决了,接受答案,并最终在**首先**之后发表第二个问题**自己研究新问题。 – luk2302

回答

1

Ť他的问题是CountingCountdown是两个不同的单词。

+0

启动它并不会崩溃,但计时器只会减少1,然后冻结 – Fman

+0

这是一个不同的问题。提示:每次调用Countdown时,都要查看Countdown例程中TimerCount变量的情况。顺便说一句,变量名应该以小写字母开头。 – vacawama

+0

谢谢,这完美解决了这个问题。 – Fman