澄清:下面描述的带有单例的视图控制器本身可以正常工作。但是,当嵌入到 UITabBarController 中时,它不起作用。
原标题:NSUnknownKeyException:可能不是笔尖,会不会是单例?
这是另一个“NSUnknownKeyException...此类不符合键的键值编码”问题,这些问题在这里很丰富。我经历了很多!这是完整的投诉:
NSUnknownKeyException', reason: '[<UIProxyObject 0x683dfe0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key button1.'
似乎这些例外总是归结为笔尖遗留的变量问题,这些变量在其他地方已更改并且没有被清除。所以我已经完成了我所有的笔尖,断开连接,重新连接,检查无济于事。然后我删除了笔尖并从零开始重建它,我仍然遇到同样的问题:-(所以我再次转向 SO 的蜂巢思维。
通过一系列NSLog
s 和其他技巧,我知道问题出在 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;
}
对不起。那很长。我已经尽可能地解决了这是一个笔尖问题。也许这是我需要启动的那些单身人士的问题?该项目的先前版本没有标签栏控制器,其中这些单例(以及其他未显示的)工作得很好。
建议赞赏!