我是一名开发 iPhone 应用程序的初学者程序员。我想知道是否有人可以帮助我解决我的应用程序中的错误。在 XCode 上编程时,我发现我的应用程序在添加更多代码后突然在启动时崩溃。输出面板显示以下错误:
* 由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[setValue:forUndefinedKey:]:此类不符合键值编码的键播放。” * First throw call stack: (0x1c91012 0x10cee7e 0x1d19fb1 0xb7ae41 0xafc5f8 0xafc0e7 0xb26b58 0x230019 0x10e2663 0x1c8c45a 0x22eb1c 0xf37e7 0xf3dc8 0xf3ff8 0xf4232 0x433d5 0x4376f 0x43905 0x8eceab6 0x4c917 0x1096c 0x1194b 0x22cb5 0x23beb 0x15698 0x1becdf9 0x1becad0 0x1c06bf5 0x1c06962 0x1c37bb6 0x1c36f44 0x1c36e1b 0x1117a 0x12ffc 0x222d 0x2155) libc++abi.dylib :终止称为抛出异常(lldb)
应用程序终止时显示的代码如下
#import <UIKit/UIKit.h>
#import "CIAAppDelegate.h"
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([CIAAppDelegate class]));
}
}
我的 ViewController.h 显示:
#import <UIKit/UIKit.h>
@interface CIAViewController : UIViewController {
IBOutlet UILabel *cruzia;
IBOutlet UILabel *textarea;
IBOutlet UIButton *playbtn;
IBOutlet UIButton *tutorialbtn;
IBOutlet UIButton *optionsbtn;
IBOutlet UIButton *trainingbtn;
IBOutlet UIButton *back;
}
-(IBAction)press;
-(IBAction)press2;
-(IBAction)press3;
-(IBAction)press4;
-(IBAction)press5;
我的 ViewController.m 也显示
#import "CIAViewController.h"
@interface CIAViewController ()
@end
@implementation CIAViewController
-(IBAction)press {
cruzia.hidden = 0;
textarea.hidden = 0;
playbtn.hidden = 1;
tutorialbtn.hidden = 1;
optionsbtn.hidden = 1;
trainingbtn.hidden = 1;
back.hidden = 0;
cruzia.text = @"Play";
textarea.text = @"Hello! You are playing the game of Cruzia!";
}
-(IBAction)press2 {
cruzia.hidden = 0;
textarea.hidden = 0;
playbtn.hidden = 1;
tutorialbtn.hidden = 1;
optionsbtn.hidden = 1;
trainingbtn.hidden = 1;
back.hidden = 0;
cruzia.text = @"Tutorial";
textarea.text = @"Welcome! You are watching the Cruzia tutorial!";
}
-(IBAction)press3 {
cruzia.hidden = 0;
textarea.hidden = 0;
playbtn.hidden = 1;
tutorialbtn.hidden = 1;
optionsbtn.hidden = 1;
trainingbtn.hidden = 1;
back.hidden = 0;
cruzia.text = @"Options";
textarea.text = @"You are now in the Options screen. You can edit the settings of the game!";
}
-(IBAction)press4 {
cruzia.hidden = 0;
textarea.hidden = 0;
playbtn.hidden = 1;
tutorialbtn.hidden = 1;
optionsbtn.hidden = 1;
trainingbtn.hidden = 1;
back.hidden = 0;
cruzia.text = @"Training";
textarea.text = @"This is the training area. You can improve your Cruzia skills here!";
}
-(IBAction)press5 {
cruzia.hidden = 0;
textarea.hidden = 0;
playbtn.hidden = 0;
tutorialbtn.hidden = 0;
optionsbtn.hidden = 0;
trainingbtn.hidden = 0;
back.hidden = 1;
cruzia.text = @"Cruzia";
}
- (void)viewDidLoad
{
textarea.hidden = 1;
playbtn.hidden = 0;
tutorialbtn.hidden = 0;
optionsbtn.hidden = 0;
trainingbtn.hidden = 0;
back.hidden = 1;
cruzia.text = @"Cruzia";
[super viewDidLoad];
}
@end
很抱歉浪费您的时间,但我已经遇到这个错误很长时间了,如果您有解决方案,我会很高兴。