首页 文章

我的应用程序将无法运行...因为AppDelagate未更改?

提问于
浏览
0

我的应用程序运行正常,直到我添加 @IBAction . 现在我得到这个错误:

2017-06-09 07:55:35.285按[1594:102051] *由于未捕获的异常'NSUnknownKeyException'终止应用程序,原因:'[setValue:forUndefinedKey:]:此类不是密钥值编码兼容的密钥加 . ' *第一次抛出调用堆栈:(0 CoreFoundation 0x000000010724bb0b exceptionPreprocess 171 1 libobjc.A.dylib 0x00000001044f3141 objc_exception_throw 48 2 CoreFoundation 0x000000010724ba59 - [NSException raise] 9 3 Foundation 0x0000000104008e8b - [NSObject(NSKeyValueCoding)setValue:forKey:] 292 4 UIKit 0x0000000104b60644 - [ UIViewController setValue:forKey:] 87 5 UIKit 0x0000000104dcd6b9 - [UIRuntimeOutletConnection connect] 109 6 CoreFoundation 0x00000001071f1e8d - [NSArray makeObjectsPerformSelector:] 269 7 UIKit 0x0000000104dcc06f - [UINib instantiateWithOwner:options:] 1856 8 UIKit 0x0000000104b66c73 - [UIViewController _loadViewFromNibNamed:bundle:] 381 9 UIKit 0x0000000104b67589 - [UIViewController loadView] 177 10 UIKit 0x0000000104b678ba - [UIViewController loadViewIfRequired] 195 11 UIKit 0x0000000104b6810a - [UIViewController视图] 27 12 UIKit 0x0000000104a3063a - [UIWindow addRootViewControllerViewIfPossible] 65 13 UIKit 0x0000000104a30d20 - [UIWindow _setHidden:f orced:] 294 14 UIKit 0x0000000104a43b6e - [UIWindow makeKeyAndVisible] 42 15 UIKit 0x00000001049bd31f - [UIApplication _callInitializationDelegatesForMainScene:transitionContext:] 4346 16 UIKit 0x00000001049c3584 - [UIApplication _runWithMainScene:transitionContext:completion:] 1709 17 UIKit 0x00000001049c0793 - [UIApplication workspaceDidEndTransaction:] 182 18 FrontBoardServices 0x000000010895b5f6 __FBSSERIALQUEUE_IS_CALLING_OUT_TO_A_BLOCK 24个19 FrontBoardServices 0x000000010895b46d - [FBSSerialQueue _performNext] 186个20 FrontBoardServices 0x000000010895b7f6 - [FBSSerialQueue _performNextFromRunLoopSource] 45 21的CoreFoundation 0x00000001071f1c01 CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION 17 22的CoreFoundation 0x00000001071d70cf __CFRunLoopDoSources0 527 23的CoreFoundation 0x00000001071d65ff __CFRunLoopRun 911 24的CoreFoundation 0x00000001071d6016 CFRunLoopRunSpecific 406 25的UIKit 0x00000001049bf02f - [UIApplication的_run] 468 26 UIKit 0x00000001049c50d4 UIA pplicationMain 159 27按0x0000000103f1a877 main 55 28 libdyld.dylib 0x00000001081eb65d start 1 29 ??? 0x0000000000000001 0x0 1)libc abi.dylib:以NSException类型的未捕获异常终止

这是我的Viewcontroller代码:

import UIKit

class ViewController: UIViewController {

// OUTLETS

@IBOutlet weak var score: UILabel!
@IBAction func add(_ sender: Any) {
    add()
}

// VARIABLES

var scoreVar = 0
let levelUpAt = [50, 100, 500, 1000, 5000, 10000, 50000, 100000]
var currentLevel = 1
var toAdd = 1

// OVERRIDES

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

// FUNCTIONS

// Below code adds to the score

func add() {
    scoreVar += 1 // Adds 1 to scoreVar
    score.text = "scoreVar"; // Updates text to match
    checkForLevelUp(); // Calls the function defined in the next few days ago
}

// Below code checks if the score meets the next level requirements

func checkForLevelUp() {
    if (scoreVar - 1 < levelUpAt[currentLevel - 1]) { // Complicated math-y if statment
        currentLevel += 1
        toAdd += 1
    }
}

}

根据调试器,它似乎停留在AppDelagate的 class AppDelegate: UIResponder, UIApplicationDelegate { 行上...

1 回答

  • 0

    转到您的故事板并单击ViewController . 单击您创建的“添加”按钮 .

    Add Button

    在Outlet Inspector的右侧,删除任何提及“添加”按钮的内容 .

    Outlets to remove

    最后,通过选项从按钮拖动到视图控制器并将类型设置为“操作”来重新创建插座 .

    New outlet to create

相关问题