昨晚,当我去测试时,我正在使用我的iOS应用程序,它在启动时崩溃了。我甚至没有处理导致崩溃的笔尖。无论如何,这是错误代码:
2/29/12 10:32:05.291 AM Safe Flight: *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIApplication 0xdd496f0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Airport1.'
*** First throw call stack:
(0x2873052 0x33add0a 0x2872f11 0x1ae2032 0x1a53f7b 0x1a53eeb 0x1a6ed60 0x136191a 0x2874e1a 0x27de821 0x136046e 0x1362010 0x114214a 0x1142461 0x11417c0 0x1150743 0x11511f8 0x1144aa9 0x37b7fa9 0x28471c5 0x27ac022 0x27aa90a 0x27a9db4 0x27a9ccb 0x11412a7 0x1142a9b 0x3710 0x2f35)
Airport1只是一个标有IBOutlet 正确的标签。此外,如果我删除连接错误只是与下一个有连接的项目。
另外,我的FileOwners类正确设置了相应的viewController。
// MasterViewController.h
#import <UIKit/UIKit.h>
#import "MobclixAds.h"
@class DataViewController;
@class EditViewController;
@class SearchViewController;
@interface MasterViewController : UIViewController{
UILabel *Airport1;
UILabel *Airport2;
UILabel *Airport3;
UILabel *Airport4;
UILabel *Airport5;
UILabel *Airport6;
UILabel *Airport7;
UILabel *Airport8;
UILabel *Airport9;
UIButton *Airport1B;
UIButton *Airport2B;
UIButton *Airport3B;
UIButton *Airport4B;
UIButton *Airport5B;
UIButton *Airport6B;
UIButton *Airport7B;
UIButton *Airport8B;
UIButton *Airport9B;
MobclixAdView* adView;
}
@property (strong, nonatomic) DataViewController *dataViewController;
@property (strong, nonatomic) EditViewController *editViewController;
@property (strong, nonatomic) SearchViewController *searchViewController;
@property (nonatomic, retain) IBOutlet UILabel *Airport1;
@property (nonatomic, retain) IBOutlet UILabel *Airport2;
@property (nonatomic, retain) IBOutlet UILabel *Airport3;
@property (nonatomic, retain) IBOutlet UILabel *Airport4;
@property (nonatomic, retain) IBOutlet UILabel *Airport5;
@property (nonatomic, retain) IBOutlet UILabel *Airport6;
@property (nonatomic, retain) IBOutlet UILabel *Airport7;
@property (nonatomic, retain) IBOutlet UILabel *Airport8;
@property (nonatomic, retain) IBOutlet UILabel *Airport9;
@property (nonatomic, retain) IBOutlet UIButton *Airport1B;
@property (nonatomic, retain) IBOutlet UIButton *Airport2B;
@property (nonatomic, retain) IBOutlet UIButton *Airport3B;
@property (nonatomic, retain) IBOutlet UIButton *Airport4B;
@property (nonatomic, retain) IBOutlet UIButton *Airport5B;
@property (nonatomic, retain) IBOutlet UIButton *Airport6B;
@property (nonatomic, retain) IBOutlet UIButton *Airport7B;
@property (nonatomic, retain) IBOutlet UIButton *Airport8B;
@property (nonatomic, retain) IBOutlet UIButton *Airport9B;
@property(nonatomic,retain) IBOutlet MobclixAdView* adView;
@end
和
// MasterViewController.m
#import "MasterViewController.h"
#import "DataViewController.h"
#import "EditViewController.h"
#import "SearchViewController.h"
@implementation MasterViewController
@synthesize dataViewController = _dataViewController;
@synthesize editViewController = _editViewController;
@synthesize searchViewController = _searchViewController;
@synthesize Airport1, Airport2, Airport3, Airport4, Airport5, Airport6, Airport7, Airport8, Airport9;
@synthesize Airport1B, Airport2B, Airport3B, Airport4B, Airport5B, Airport6B, Airport7B, Airport8B, Airport9B;
@synthesize adView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.title = @"Safe Flight";
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Back" style:UIBarButtonItemStylePlain target:nil action:nil];
}
return self;
}
我的代码存在问题吗?还是与Xcode本身?我已经重新启动了Xcode和模拟器甚至做了一个“干净”的构建(听起来它会有所帮助......)
谢谢, 安德鲁
编辑这是我的AppDelegate,我正在向窗口设置正确的xib
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[Mobclix start];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"MasterViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:masterViewController];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}
问题已解决!!!
由于一些愚蠢的垃圾邮件过滤器,我无法回答我自己的问题......我可以发布问题的图片......但是已修复了!
但是这里是问题click here
的链接答案 0 :(得分:2)
答案 1 :(得分:1)
导致崩溃的原因可能是xib到header之间的连接错误。 Airport1可以连接到另一个类而不是MasterViewController。
如果您的标签已连接到文件所有者 - 它应为 MasterViewController 。
如果你在xib中创建了另一个UIViewController并且连接了Airport1标签,那么这个控制器也应该连接到 MasterViewController ( Identity Inspector “ Class “字段。”
更新。添加了屏幕截图:
答案 2 :(得分:0)
初始化MasterViewController时(无论您从哪里开始),请确保使用相应的nib文件对其进行初始化
实施例。
MasterViewController *masterViewController = [[MasterViewController alloc] initWithNibName:@"YourNibName" bundle:nil];