Swift 2 arc4random_uniform崩溃?

时间:2016-02-06 19:54:19

标签: ios swift2

我有一个非常简单的执行,但由于某种原因它崩溃了。有什么想法吗?

import UIKit  
class ViewController: UIViewController {

@IBOutlet var myTextField: UITextField!
@IBOutlet var resultsLabel: UILabel!

@IBAction func pressButton(sender: AnyObject) {
    let diceRoll = String(arc4random_uniform(UInt32(6)))
    print(diceRoll)
}

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.
}

已添加崩溃日志

  

2016-02-06 16:24:32.358 GuessingGame [6330:496415] *终止应用   由于未被捕获的异常'NSUnknownKeyException',原因:'[   setValue:forUndefinedKey:]:此类不是键值   符合编码的关键TextField。' *第一次抛出调用堆栈:(0   CoreFoundation 0x000000010960ae65 exceptionPreprocess + 165 1   libobjc.A.dylib 0x000000010b34adeb objc_exception_throw + 48 2   CoreFoundation 0x000000010960aaa9 - [NSException raise] + 9 3   基金会0x00000001099d39bb - [NSObject(NSKeyValueCoding)   setValue:forKey:] + 288 4 UIKit 0x0000000109fb6320 - [UIViewController   setValue:forKey:] + 88 5 UIKit 0x000000010a1e4f41    - [UIRuntimeOutletConnection connect] + 109 6 CoreFoundation 0x000000010954b4a0 - [NSArray makeObjectsPerformSelector:] + 224 7   UIKit 0x000000010a1e3924 - [UINib instantiateWithOwner:options:] + 1864   8 UIKit 0x0000000109fbceea - [UIViewController   _loadViewFromNibNamed:bundle:] + 381 9 UIKit 0x0000000109fbd816 - [UIViewController loadView] + 178 10 UIKit 0x0000000109fbdb74 - [UIViewController loadViewIfRequired] + 138 11 UIKit 0x0000000109fbe2e7 - [UIViewController view] + 27 12 UIKit   0x0000000109e94ab0 - [UIWindow addRootViewControllerViewIfPossible] +   61 13 UIKit 0x0000000109e95199 - [UIWindow _setHidden:forced:] + 282 14   UIKit 0x0000000109ea6c2e - [UIWindow makeKeyAndVisible] + 42 15 UIKit   0x0000000109e1f663 - [UIApplication   _callInitializationDelegatesForMainScene:transitionContext:] + 4131 16 UIKit 0x0000000109e25cc6 - [UIApplication   _runWithMainScene:transitionContext:completion:] + 1760 17 UIKit 0x0000000109e22e7b - [UIApplication workspaceDidEndTransaction:] + 188   18 FrontBoardServices 0x000000010d1df754 - [FBSSerialQueue   _performNext] + 192 19 FrontBoardServices 0x000000010d1dfac2 - [FBSSerialQueue _performNextFromRunLoopSource] + 45 20 CoreFoundation 0x0000000109536a31   __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 21 CoreFoundation 0x000000010952c95c __CFRunLoopDoSources0 + 556 22   CoreFoundation 0x000000010952be13 __CFRunLoopRun + 867 23   CoreFoundation 0x000000010952b828 CFRunLoopRunSpecific + 488 24 UIKit   0x0000000109e227cd - [UIApplication _run] + 402 25 UIKit   0x0000000109e27610 UIApplicationMain + 171 26 GuessingGame   0x000000010942b4dd main + 109 27 libdyld.dylib 0x000000010be5392d   start + 1)libc ++ abi.dylib:以未捕获的异常终止   输入NSException(lldb)

1 个答案:

答案 0 :(得分:1)

最有可能的原因是您在代码中将您的IBOutlet从TextField重命名为myTextField(或者添加了一个新链接,但没有从IB中的控件中删除旧引用)。