澄清:下面描述的带有单例的视图控制器本身可以正常工作。但是,当嵌入到UITabBarController中时,它不起作用。
原标题:NSUnknownKeyException:可能不是笔尖,它可能是单身吗?
这是另一个“NSUnknownKeyException ......这个类不是关键值编码兼容的关键”问题,这里有很多。我经历过很多次!以下是完整的投诉:
NSUnknownKeyException', reason: '[<UIProxyObject 0x683dfe0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key button1.'
似乎这些异常总是归结为笔尖留下的问题,这些问题已经遗留在其他地方并且没有被清理掉的变量。所以我已经完成了所有的笔尖,断开连接,重新连接,检查无济于事。然后我删除了笔尖,并从零重建它,我仍然有同样的问题:-(所以我再次转向SO的蜂巢头脑。
通过一系列NSLog
和其他技巧,我知道问题出在GameViewController上(如果我摆脱它并用空控制器替换它,应用程序工作正常)。以下是GameViewController的相关部分:
@interface GameViewController : UIViewController <UIAlertViewDelegate>
@end
@implementation GameViewController
- (id) init {
NSLog(@" GVC initializing");
self = [super initWithNibName:@"GameViewController"
bundle:nil];
if (self) {
UITabBarItem *tbi = [self tabBarItem];
[tbi setTitle:@"Play Game"];
}
return self;
}
- (id) initWithNibName:(NSString *)nibName bundle:(NSBundle *)Bundle {
return [self init];
}
- (void)loadView {
[super loadView];
NSLog(@"loadView is starting");
// Set up display of button and label singletons
NSMutableArray *keyArray;
NSMutableArray *valueArray;
keyArray = [NSMutableArray arrayWithObjects:@"answerButtons", @"clueLabels", @"keyPad", nil];
valueArray = [NSMutableArray arrayWithObjects: [AnswerButtons answerButtons], [ClueLabels clueLabels], [KeyPad keyPad], nil];
NSMutableDictionary *externals = [NSMutableDictionary dictionaryWithObjects:valueArray
forKeys:keyArray];
// Fire the button and label singletons
[[AnswerButtons answerButtons] answerButtonsDidLoad];
[[ClueLabels clueLabels] clueLabelsDidLoad];
[[KeyPad keyPad] keyPadDidLoad];
// Set up nibOptions and link to externals
NSDictionary *nibOptions = [NSDictionary dictionaryWithObject:externals
forKey:UINibExternalObjects];
[self.nibBundle loadNibNamed:self.nibName owner:self options:nibOptions];
NSLog(@"loadView is done");
}
@end
以下是我的应用代表的相关部分:
@implementation AppDelegate
@synthesize window = _window;
@synthesize tbc = _tbc;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSLog(@"dFLWO starting");
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
UITabBarController *tbc = [[UITabBarController alloc] init];
SettingsViewController *settingsVC = [[SettingsViewController alloc] init];
GameViewController *gameVC = [[GameViewController alloc] init];
// UIViewController *temp = [[UIViewController alloc] init]; // works fine
NSLog(@"dFLWO: both VC's inited");
[tbc setViewControllers:[NSArray arrayWithObjects:gameVC, settingsVC, nil]];
// [tbc setViewControllers:[NSArray arrayWithObjects: temp, settingsVC, nil]]; // works fine
NSLog(@"dFLWO: VC's set");
[[self window] setRootViewController:tbc];
[self.window makeKeyAndVisible];
NSLog(@"TabBarController now active");
return YES;
}
对不起。那很长。我尽可能地走了,因为这是一个笔尖问题。也许这是我需要推出的那些单身人士的问题?这个项目的先前版本没有标签栏控制器,其中这些单例(和其他未显示的)工作得很好。
建议赞赏!