明確化: 以下に説明するシングルトンを含むビュー コントローラーは、単独で正常に動作します。ただし、UITabBarController に埋め込むと、機能しません。
元のタイトル: NSUnknownKeyException: おそらくニブではなく、シングルトンでしょうか?
ここでは、「NSUnknownKeyException ... このクラスは、キーのキー値コーディングに準拠していません」という質問のさらに別の 1 つを示します。私はそれらの多くを経験してきました!苦情の全文は次のとおりです。
NSUnknownKeyException', reason: '[<UIProxyObject 0x683dfe0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key button1.'
これらの例外は常に、他の場所で変更されてクリーンアップされなかった変数が nib に残っているという問題に帰着するようです。それで、私はペン先をすべて切断し、再接続し、無駄にチェックしました. 次に、ペン先を削除してゼロから再構築しましたが、まだ同じ問題があります:-(だから、もう一度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;
}
ごめん。それは長いです。これはニブの問題であるため、できる限り行ってきました。おそらく、起動する必要があるシングルトンに問題があるのでしょうか? このプロジェクトの以前のバージョンでは、これらのシングルトン (および表示されていない他のシングルトン) が正常に機能する、タブ バー コントローラーがありませんでした。
提案を歓迎します!