2012-06-11 1 views
0

iOS5가 포함 된 xcode에서 스토리 보드를 사용하고 있습니다. 탭이 6 개인 TabBarController가 있습니다. TabController 이전에 사용자는 A oR B 계정 유형을 선택합니다. B 유형이 선택되면 탭 중 하나를 숨기고 싶습니다.iOS5 setHidden UITabBarItem이 충돌을 일으킴

저는 UITabBarController의 하위 클래스가 있는데이 코드는 작동하지만 원하는 것은 아닙니다.

if (accountType == 2) { 
    [[[[self tabBar] items] objectAtIndex:1] setEnabled:NO]; 
} 

이 내 두 번째 탭은 어둡고 확인되는 사용할 수 있습니다,하지만 난 정말이 일을하고 싶어 ...

[[[[self tabBar] items] objectAtIndex:1] setHidden:YES]; 

을하지만이 오류가 발생합니다 - [UITabBarItem setHidden :] : 인식 할 수없는 선택기 인해 캐치되지 않는 예외 'NSInvalidArgumentException'응용 프로그램 종료, 이유 인스턴스 0x856f490 * 전송 -

'[UITabBarItem setHidden는 :] 미정 선택기 인스턴스 0x856f490 전송' 이것을 달성하는 다른 방법이 있습니까?

답변

1

사용자가 어떤 유형의 계정을 선택하는지 알 때까지 tabBar보기 제어기의 초기화를 기다리지 않는 이유는 무엇입니까? 그렇게하려면 setViewControllers:animated: 방법을 사용하십시오. 귀하의 오류 메시지에 대해서는

When you assign a new set of view controllers runtime, the tab bar controller removes all of the old view controllers before installing the new ones. When changing the view controllers, the tab bar controller remembers the view controller object that was previously selected and attempts to reselect it. If the selected view controller is no longer present, it attempts to select the view controller at the same index in the array as the previous selection. If that index is invalid, it selects the view controller at index 0.

:

if (accountType == 1) { 
    NSArray* controllersForTabBar = [NSArray arrayWithObjects:myVC1,myVC2,myVC3,myVC4,myVC5,myVC6 nil]; 
    [[[self tabBar] setViewControllers:controllersForTabBar] animated:YES]; 
} 
if (accountType == 2) { 
    NSArray* controllersForTabBar = [NSArray arrayWithObjects:myVC1,myVC2,myVC3,myVC4,myVC5, nil]; 
    [[[self tabBar] setViewControllers:controllersForTabBar] animated:YES]; 
} 

이 방법에 대한 사과 의사는 말한다 : 다음과 같이 한 tabBar이 방법 setHidden:를 구현하지 않기 때문에 당신은 그 오류가 발생합니다.

1

d.ennis 대답은 올바른 방향으로 나를 가리켰다. 스토리 보드와 함께 ios5를 위해 약간 조정해야합니다 ...

+0

나는 코드가 100 % 쓸 수는 없지만 아이디어를 얻는다는 것을 알고 있습니다. :) – Andy