2012-11-27 5 views
1

저는 기능을 사용하기 전에 로그인 또는 가입하도록 사용자에게 묻는 iOS 앱을 개발 중입니다. 흐름은 다음과 같습니다. 앱에 2 개의 버튼이있는 화면이 표시됩니다. 1) 로그인 2) 등록 버튼을 클릭하면 앱이 UiNavigationController를 사용하여 여러보기 컨트롤러로 이동합니다. 로그인에 성공하면 사용자는보기 하단에 탭 막대를 표시하고보기 상단에 UiNavigationController의 위쪽 막대를 표시하는 홈보기 컨트롤러로 이동합니다.UINavigationController와 UITabBarController를 결합하십시오.

이를 구현하기 위해 AppDelegate 파일의 루트보기 컨트롤러로 UINavigationViewController를 설정했습니다.

사용자가 인증 되 자마자 다음 코드를 사용하여 UiNavigationController에서 탭 표시 줄 컨트롤러를 밀었습니다.

FirstViewController *firstViewController = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil]; 
    [firstViewController setTabBarItem:[[UITabBarItem alloc] initWithTitle:@"1st" image:[UIImage imageNamed:@"1st.png"] tag:101]]; 

    SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil]; 
    [secondViewController setTabBarItem:[[UITabBarItem alloc] initWithTitle:@"2nd" image:[UIImage imageNamed:@"2nd.png"] tag:102]]; 

    ThirdViewController *thirdViewController = [[ThirdViewController alloc]initWithNibName:@"ThirdViewController" bundle:nil]; 
    [thirdViewController setTabBarItem:[[UITabBarItem alloc] initWithTitle:@"3rd" image:[UIImage imageNamed:@"3rd.png"] tag:104]]; 


    UITabBarController *tabController = [[UITabBarController alloc] init]; 
    [tabController setViewControllers:[NSArray arrayWithObjects:firstViewController, secondViewController,thirdViewController, nil]]; 

    [self.navigationController pushViewController:tabController animated:YES]; 

이 방법이 맞습니까? 누군가는 방금 루트보기 컨트롤러로 탭 막대 컨트롤러를 사용하는 것이 더 나은 접근 방법이라고 말했습니다. 로그인/가입 화면에 탭 표시 줄을 표시하고 싶지 않으므로 어떻게 탭 컨트롤러를 루트보기 컨트롤러로 설정할 수 있습니까?

고마워요!

답변

0

로그인을 UIViewControllerAppDelegate 사이에서 통신 할 수 있도록 프로토콜을 만드십시오. 로그인이 완료되면 rootViewController을 변경할 수 있습니다. 당신은 또한 뭔가를 수행하여 AppDelegate에 대한 참조를 얻을 수 있습니다 :

MyAppDelegate *appDelegate = (MyAppDelegate *)[[UIApplication sharedApplication] delegate]; 

내가 다른 개체 간의 통신 프로토콜을 사용하는 것을 선호하지만.

관련 문제