###概要
初心者です。ボタンを押すとテキストが切り替わるようなものを作ろうと思い、UIKitを使って以下を記述しました。
import UIKit class ViewController: UIViewController { @IBOutlet weak var myLabel: UILabel! @IBAction func buttonPressed(sender: AnyObject) { myLabel.text = "Button Pressed!" }
しかし、シミュレータを立ち上げようとするとクラッシュし、以下の様なエラーが出ます。どうすれば解決できるでしょうか?
「this class is not key value coding-compliant for the key myButton」が問題だとは分かるのですが、対処法が分かりませんでした。
【エラー箇所】AppDelegate.swift
class AppDelegate: UIResponder, UIApplicationDelegate {
【ログ】
2015-04-09 10:33:50.495 ButtonTutorial[9866:505128] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ButtonTutorial.ViewController 0x7ff94143bfb0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key myButton.' *** First throw call stack: ( 0 CoreFoundation 0x00000001026bea75 __exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000104216bb7 objc_exception_throw + 45 2 CoreFoundation 0x00000001026be6b9 -[NSException raise] + 9 3 Foundation 0x0000000102ad9d43 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 259 4 CoreFoundation 0x00000001026085e0 -[NSArray makeObjectsPerformSelector:] + 224 5 UIKit 0x00000001032184ed -[UINib instantiateWithOwner:options:] + 1506 6 UIKit 0x0000000103076a88 -[UIViewController _loadViewFromNibNamed:bundle:] + 242 7 UIKit 0x0000000103077078 -[UIViewController loadView] + 109 8 UIKit 0x00000001030772e9 -[UIViewController loadViewIfRequired] + 75 9 UIKit 0x000000010307777e -[UIViewController view] + 27 10 UIKit 0x0000000102f96509 -[UIWindow addRootViewControllerViewIfPossible] + 58 11 UIKit 0x0000000102f968a1 -[UIWindow _setHidden:forced:] + 247 12 UIKit 0x0000000102fa2f8c -[UIWindow makeKeyAndVisible] + 42 13 UIKit 0x0000000102f4d0c2 -[UIApplication _callInitializationDelegatesForMainScene:transitionContext:] + 2732 14 UIKit 0x0000000102f4fe3e -[UIApplication _runWithMainScene:transitionContext:completion:] + 1349 15 UIKit 0x0000000102f4ed35 -[UIApplication workspaceDidEndTransaction:] + 179 16 FrontBoardServices 0x0000000105dc8243 __31-[FBSSerialQueue performAsync:]_block_invoke + 16 17 CoreFoundation 0x00000001025f3c7c __CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12 18 CoreFoundation 0x00000001025e99c5 __CFRunLoopDoBlocks + 341 19 CoreFoundation 0x00000001025e9785 __CFRunLoopRun + 2389 20 CoreFoundation 0x00000001025e8bc6 CFRunLoopRunSpecific + 470 21 UIKit 0x0000000102f4e7a2 -[UIApplication _run] + 413 22 UIKit 0x0000000102f51580 UIApplicationMain + 1282 23 ButtonTutorial 0x00000001024dfede top_level_code + 78 24 ButtonTutorial 0x00000001024dff1a main + 42 25 libdyld.dylib 0x00000001049f2145 start + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)
###開発環境
- iOS:8.2
- Xcode:6.2
- 使用言語:swift
- ios Simulator:iphone6
下記のような回答は推奨されていません。
このような回答には修正を依頼しましょう。
また依頼した内容が修正された場合は、修正依頼を取り消すようにしましょう。
2015/04/09 03:00
2018/04/28 10:53