5

私の要件は、 UITabBarController が rootviewcontroller であり、アプリの初回起動時に UINavCon 内にあるログイン手順を表示したいということですpresentViewController

UITabBarController を初めて表示したくないし、ログイン UINavCon がモーダルとしてポップアップする方法も望んでいません。

初めてアプリを起動すると、ログイン UINavCon が表示されるユーザーエクスペリエンスを実現したいと考えています。だからここに私のコードがあります:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

[self.window makeKeyAndVisible];//is it correct to call it here?

LoginVC *loginObj = [[LoginVC alloc]init];

self.navigationController = [[UINavigationController alloc] initWithRootViewController:cellPhoneNumber];

self.tabBarController = [[UITabBarController alloc]init];

self.window.rootViewController = self.tabBarController;

[self.tabBarController presentViewController:self.navigationController animated:NO completion:^{}];

return YES;
}

[self.window makeKeyAndVisible];の直後に 2 番目の回線で呼び出していuiwindow alloc initます。そうしないと、ビューコントローラーがイベントや向きの通知を受信しないなどの問題が発生する可能性がありますか?

4

2 に答える 2

5

実装を使用してコードが機能するかどうかについては言及していません。とにかく、私は最近、ログインコントローラーを提示し、ログイン後に tabBarController を提示する必要がある同様の種類の実装を行ったので、私の実装を共有するだけです。

  1. ログイン コントローラを作成し、didFinishLaunchingメソッドで提示します。

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    LoginController *loginCObj= [[[MainScreenController alloc]init]autorelease];
    UINavigationController *navigationControllerObj = [[[UINavigationController alloc]initWithRootViewController:loginObj]autorelease];
    self.window.rootViewController = navigationControllerObj;
    [self.window makeKeyAndVisible];
    
  2. その後、ログイン ビュー コントローラーでログインに成功したら、appDelegate パブリック メソッドを呼び出します。

    ログインコントローラーで

    AppDelegate *appDel = (AppDelegate *)[[UIApplication sharedApplication] delegate];
    [appDel  applicationLoggedInSuccesfully];
    

    appDelegate ファイルに、次のようなメソッドを追加します。

    -(void)applicationLoggedInSuccesfully{
        UINavigationController *nv1 = [[[UINavigationController alloc] initWithNibName:nil bundle:nil]autorelease];
        TabController1 *v1 = [[[TabController1 alloc] initWithNibName:nil bundle:nil]autorelease];
        [nv1 pushViewController:v1 animated:NO];
    
        UITabBarController *tabController = [[[UITabBarController alloc] init]autorelease];
        tabController.viewControllers = @[nv1];
        tabController.delegate = self;
        self.window.rootViewController = tabController;
        [self.window makeKeyAndVisible];
    }
    

それがあなたを助けることを願っています。

于 2013-07-18T06:32:16.983 に答える