タブ付きの iPhone アプリケーションを作成しています。アプリケーションの起動時に、ユーザーがログインしていない場合、モーダル ビューがタブ バー コントローラーの上部に表示されるはずです (したがって、これが最初の画面のように見えます)。ログインすると、モーダル ビューがスライドして離れ、その背後にあるタブ バー コントローラーが表示されます。
残念ながら[self.tabBarController presentViewController:self.loginViewController animated:NO completion:NULL]
、アプリケーション デリゲート内から呼び出すと、画面の下部にまだタブが表示されます。私はそれらをカバーする必要があります。
皮肉なことに、解決策を探していると、ほとんどの人が逆の問題を抱えていることがわかります。
ウィンドウの rootViewControllerをUITabBarController に設定せず、そのビューをウィンドウのサブビューとして挿入するだけで、期待どおりに動作することに気付きましたが、Xcode は rootViewController の欠如について不平を言います。何が起きてる?
私のアプリケーション デリゲートの-application:didFinishLaunchingWithOptions:
メソッドは次のようになります。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self registerDefaults];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = @[
[self makeSellingListingsController],
[[[UIViewController alloc] init] autorelease], // stub
[[[UIViewController alloc] init] autorelease], // stub
[[[UIViewController alloc] init] autorelease] // stub
];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
self.window.rootViewController = self.tabBarController;
[self.window addSubview:self.tabBarController.view];
[self presentLogin]; // this doesn't cover the tabs, but it should
[self.window makeKeyAndVisible];
return YES;
}
- (void)presentLogin
{
[self.tabBarController presentViewController:[[[FLLoginViewController alloc]
initWithNibName:@"FLLoginViewController"
bundle:[NSBundle mainBundle]] autorelease]
animated:NO
completion:NULL];
}