2010-08-21 4 views
1

Interfacebuilder에서 설정 한 UITabbarController가 있습니다. tabbarcontroller에는 5 개의 탭이 있으며 첫 번째 페이지는 시작 페이지이고 두 번째 페이지는 UITableViewController입니다. 둘 다 NavigationController가 있습니다. 두 번째 탭에는 카테고리 목록이 표시됩니다. 앱을 실행하면 모두 정상입니다. 두 번째 탭을 누르면 네비게이션 컨트롤러로보기가 완벽하게로드됩니다. 하지만 내가하고 싶은 일은 첫 번째 탭의 링크를 사용하여 두 번째 탭에 특정 카테고리를로드 할 수있게하려는 것입니다.UITabbarController 설정보기

그래서 제가 한 일은 내 AppDelegate에에 다음과 같은 기능을 추가했고 전화 내 첫 번째 탭의보기에서이다 :

- (void)loadCategoryViewUsingCategoryId:(NSString*)categoryId 
{ 
    CategoryViewController *categoryView = [[CategoryViewController alloc] initWithLoadingCategoryUsingCategoryId:categoryId]; 

    if (!categoryView) { 
     UIAlertView *errorView; 
     errorView = [[UIAlertView alloc] 
        initWithTitle: NSLocalizedString(@"Whoops", @"oddsAppAppDelegate") 
        message: NSLocalizedString(@"I did not found the requested category. Sorry!", @"oddsAppAppDelegate") 
        delegate: self 
        cancelButtonTitle: NSLocalizedString(@"Close", @"oddsAppAppDelegate") otherButtonTitles: nil]; 
     [errorView show]; 
     [errorView autorelease]; 
    } 
    else { 
     self.tabBarController.selectedIndex = 1; 

     self.tabBarController.selectedViewController = categoryView; 
     [self.tabBarController.selectedViewController setTitle:@"apa"]; 
     [self.tabBarController.selectedViewController viewDidLoad]; 
    } 
} 

이 완벽하게 작동,하지만 ... 2 탭을로드 탐색 컨트롤러 도구 모음이 없습니다. 내 탐색 컨트롤러 도구 모음을 유지하려면 어떻게로드 할 수 있습니까?

"CategoryViewController"은 덧붙여서 UITableViewController입니다.

안부,
폴 Peelen

답변

1

탐색 바는 기본적으로 표시한다.

[[self navigationController] setNavigationBarHidden:NO]; 

으로 직접 액세스하려는 경우 문제가 다른 곳에서 발생한다고 생각합니다. 이

UITabBarController *theTabBar = [[UITabBarController alloc]init]; 
YourWelcomeViewClassHere *welcome = [[YourWelcomeViewClassHere alloc] initWithNibName:@"YourWelcomeViewClassHere" bundle:nil]; //Or other custom initalizers 
UINavigationController *welcomeNav = [[UINavigationController alloc] initWithRootViewController:welcome]; 
CategoryViewController *category = [[CategoryViewController alloc] initWithNibName:@"CategoryViewController" bundle:nil]; //Or other custom initalizers 
UINavigationController *categoryNav = [[UINavigationController alloc] initWithRootViewController:category]; 
/* 
Your other View controllers initializations 
*/ 

NSArray *viewControllers = [[NSArray alloc] initWithObjects:welcomeNav,categoryNav,/* other viewControllers ,*/nil]; 
[theTabBar setViewControllers:viewControllers]; 

처럼 컨트롤러를 지정하면이 일을하고 귀하의 의견을 표시 할 수 있습니다.

+0

안녕하세요, 나는 그것을 시도했지만 실제로는 효과가 없습니다. 그럼 다시, 귀하의 게시물을 생각하고 나에게 다음과 같은 해결책을 준 시작 : \t \t self.tabBarController.selectedIndex = 1; \t \t UINavigationController * nav = [self.tabBarController.viewControllers objectAtIndex : 1]; \t \t nav.viewControllers = [[NSArray alloc] initWithObjects : categoryView, nil]; 이것은 나를 위해 일했습니다. 감사합니다, Paul Peelen –