由于AppDelegate未更改,我的应用程序无法运行?

时间:2017-06-09 13:06:57

标签: ios swift

我的应用程序运行正常,直到我添加@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基础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:forced:] + 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 UIApplicationMain + 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.
}

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

}

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

1 个答案:

答案 0 :(得分:0)

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

Add Button

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

Outlets to remove

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

New outlet to create