-1

我对 swift 非常陌生,非常陌生,问这个问题我可能会觉得自己像个白痴。我非常简单的目标是,当我的按钮被点击时,按钮的标题会消失,但不幸的是,每次我运行它时应用程序都会崩溃,我不知道我做错了什么。感谢您的帮助。

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var background1: UIImageView!
@IBOutlet weak var screenButton: UIButton!

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

    self.screenButton.setTitle("Tap!", forState: UIControlState.Normal)
}

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

@IBAction func screenTapped(sender: AnyObject) {
    self.screenButton.setTitle("", forState: UIControlState.Normal)
}

}
2015-04-10 17:13:41.465 TopScore[6391:414281] *** 由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:此类不符合键值编码关键屏幕已点击。
*** 首先抛出调用堆栈:
(
    0 核心基础 0x0000000104fc0a75 __exceptionPreprocess + 165
    1 libobjc.A.dylib 0x0000000106b18bb7 objc_exception_throw + 45
    2 核心基础 0x0000000104fc06b9 -[NSException raise] + 9
    3 基础 0x00000001053dbd43 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259
    4 核心基础 0x0000000104f0a5e0 -[NSArray makeObjectsPerformSelector:] + 224
    5 UIKit 0x0000000105b1a4ed-[UINib instantiateWithOwner:options:] + 1506
    6 UIKit 0x0000000105978a88-[UIViewController _loadViewFromNibNamed:bundle:] + 242
    7 UIKit 0x0000000105979078-[UIViewController loadView] + 109
    8 UIKit 0x00000001059792e9-[UIViewController loadViewIfRequired] + 75
    9 UIKit 0x000000010597977e-[UIViewController 视图] + 27
    10 UIKit 0x0000000105898509-[UIWindow addRootViewControllerViewIfPossible] + 58
    11 UIKit 0x00000001058988a1-[UIWindow _setHidden:forced:] + 247
    12 UIKit 0x00000001058a4f8c -[UIWindow makeKeyAndVisible] + 42
    13 UIKit 0x000000010584f0c2-[UIApplication_callInitializationDelegatesForMainScene:transitionContext:] + 2732
    14 UIKit 0x0000000105851e3e-[UIApplication_runWithMainScene:transitionContext:completion:] + 1349
    15 UIKit 0x0000000105850d35-[UIApplication workspaceDidEndTransaction:] + 179
    16 FrontBoardServices 0x00000001086ca243 __31-[FBSSerialQueue performAsync:]_block_invoke + 16
    17 核心基础 0x0000000104ef5c7c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    18 核心基础 0x0000000104eeb9c5 __CFRunLoopDoBlocks + 341
    19 核心基础 0x0000000104eeb785 __CFRunLoopRun + 2389
    20 核心基础 0x0000000104eeabc6 CFRunLoopRunSpecific + 470
    21 UIKit 0x00000001058507a2-[UIApplication_run] + 413
    22 UIKit 0x0000000105853580 UIApplicationMain + 1282
    23 TopScore 0x0000000104de1cee top_level_code + 78
    24 TopScore 0x0000000104de1d2a 主要 + 42
    25 libdyld.dylib 0x00000001072f4145 开始 + 1
    26 ???0x0000000000000001 0x0 + 1
)
libc++abi.dylib:以 NSException 类型的未捕获异常终止
(lldb)
4

1 回答 1

2

在某些时候,您不小心设置了一个名为screenTapped. 您需要在情节提要的 Interface Builder 中找到该插座并将其删除。

您想要的是按钮到screenTapped:. 动作和出口是两个非常不同的东西。

于 2015-04-10T16:33:10.213 回答