簡體   English   中英

Swift Stopwatch App崩潰,不知道我要去哪里

[英]Swift Stopwatch App crashing, don't know where I'm going wrong

我正在嘗試為正在參加的編碼課程制作秒表應用程序。 在運行代碼之前,我沒有任何錯誤,但是一旦運行它,“構建成功”后它就會崩潰。

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()

    }

    var timer = NSTimer()

    var count = 0

    func updateTime() {

        count++

        timeLabel.text = "\(count)"

    }

    @IBOutlet weak var timeLabel: UILabel!

    @IBAction func playButton(sender: AnyObject) {

        timer = NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: Selector("updateTime"), userInfo: nil, repeats: true)

    }

    @IBAction func pauseButton(sender: AnyObject) {

    }

    @IBAction func resetButton(sender: AnyObject) {

    }



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


}

這是輸出控制台:

2015-07-23 12:52:26.877 Stop Watch[7472:467329] *** Terminating app 
due to uncaught exception 'NSUnknownKeyException', reason:    
'[<Stop_Watch.ViewController   0x7ffdf1435b60> setValue:forUndefinedKey:]:
this class is not key value coding-compliant for the key play.'

*** First throw call stack:
(
  0   CoreFoundation       0x000000010a814c65 __exceptionPreprocess + 165
  1   libobjc.A.dylib      0x000000010c37fbb7 objc_exception_throw + 45
  2   CoreFoundation       0x000000010a8148a9 -[NSException raise] + 9
  3   Foundation           0x000000010ac32b53 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
  4   CoreFoundation       0x000000010a75cd50 -[NSArray makeObjectsPerformSelector:] + 224
  5   UIKit                0x000000010b38b4eb -[UINib instantiateWithOwner:options:] + 1506
  6   UIKit                0x000000010b1e36d8 -[UIViewController _loadViewFromNibNamed:bundle:] + 242
  7   UIKit                0x000000010b1e3cc8 -[UIViewController loadView] + 109
  8   UIKit                0x000000010b1e3f39 -[UIViewController loadViewIfRequired] + 75
  9   UIKit                0x000000010b1e43ce -[UIViewController view] + 27
  10  UIKit                0x000000010b0ff289 -[UIWindow addRootViewControllerViewIfPossible] + 58
  11  UIKit                0x000000010b0ff64f -[UIWindow _setHidden:forced:] + 247
  12  UIKit                0x000000010b10bde1 -[UIWindow makeKeyAndVisible] + 42
  13  UIKit                0x000000010b0af417 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2732
  14  UIKit                0x000000010b0b219e -[UIApplication _runWithMainScene:transitionContext:completion:] + 1349
  15  UIKit                0x000000010b0b1095 -[UIApplication workspaceDidEndTransaction:] + 179
  16  FrontBoardServices   0x000000010de7c5e5 __31-[FBSSerialQueue performAsync:]_block_invoke_2 + 21
  17  CoreFoundation       0x000000010a74841c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
  18  CoreFoundation       0x000000010a73e165 __CFRunLoopDoBlocks + 341
  19  CoreFoundation       0x000000010a73df25 __CFRunLoopRun + 2389
  20  CoreFoundation       0x000000010a73d366 CFRunLoopRunSpecific + 470
  21  UIKit                0x000000010b0b0b02 -[UIApplication _run] + 413
  22  UIKit                0x000000010b0b38c0 UIApplicationMain + 1282
  23  Stop Watch           0x000000010a618fa7 main + 135
  24  libdyld.dylib        0x000000010cab5145 start + 1
  25  ???                  0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb) 

查看控制台日志后,我很確定崩潰是由於缺少插座連接而發生的。

按Cmd + Shift + F並在搜索字段中鍵入“播放”。 在情節提要文件中查找形式為...: Outlet = "play"的條目。

單擊該條目,然后單擊play旁邊的“ x”按鈕將其刪除。

這應該可以解決崩潰問題。

每當您看到以下格式的錯誤時: ... this class is not key value coding-compliant for the key ...您應檢查情節提要或xib中是否缺少插座。

暫無
暫無

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

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