iOSでJSONから画面を生成する QuickDialog
QuickDialogという便利なライブラリがあります。
cocoapod経由で利用可能。
NSDictionary *json = @{ @"grouped": @YES, @"title": @"LOGIN", @"controllerName": @"LoginViewController", @"sections": @[ @{ @"title" : @"Information:", @"elements" : @[ @{ @"type" : @"QEntryElement", @"title" : @"Email", @"key" : @"email" }, @{ @"type" : @"QEntryElement", @"title" : @"Password", @"key" : @"password" } ] }, @{ @"title" : @"Sign in", @"elements" : @[ @{ @"type":@"QButtonElement", @"controllerAction" : @"onSignIn", @"title":@"Sign In" }, ] }, ] }; QRootElement *root = [[QRootElement alloc] initWithJSON:json andData:nil]; LoginViewController *lvc = (LoginViewController *)[QuickDialogController controllerForRoot:root]; [self presentViewController:[[UINavigationController alloc] initWithRootViewController:lvc] animated:YES completion:nil];
これで
iOS開発の敷居のひとつにStoryBoardがあるので、これは非iOSプログラマの人の入りとしてもとてもいいと思いました。
2014/3/18 補足
上の例でいうところの[LoginViewController new] とかってやって、LoginViewController側のviewDidLoadでself.root = [[QRootElement alloc] initWithJSON:json andData:nil]; とかってやると、QEntryElementとかで入力するときのキーボードが出るときにスクロールしなくなってしまいます。
これで結構ハマりました。