2014-06-07 10 views
1

내 응용 프로그램에 tabbarcontroller이 있는데 그 중 첫 번째가 viewcontroller이 아닙니다. navigationcontroller 양식이 열립니다 (부모로부터 스택하여 푸시).tabbarcontroller보기를 표시 할 때 탐색 모음에 RightButtonItem을 추가하십시오.

이제이보기의 탐색 줄에 rightbarbuttonitem을 추가하고 싶습니다. 나는이 코드를 사용하고 있습니다 :

UIBarButtonItem *b= [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(actionBarButtonPressed)]; 
self.navigationController.navigationItem.rightBarButtonItem= b; 

을하지만 노동 어떤되지 않은 버튼은 탐색 표시 줄에 나타나지 않습니다. 나는 이것에 대해 조사했지만 모든 주제에서이 코드는 해결책으로 응답되었습니다. 아마도 tabbarnavigationbar을 함께 사용하는 경우 다를 수 있습니다. 어느 누구도 다른 해결책을 알고 있습니까?

편집 마지막 줄에 중단 점 광고를 추가하고 일부 변수를 확인했습니다.

(lldb) po self.navigationController.navigationItem.rightBarButtonItem 
error: property 'navigationItem' not found on object of type 'id' 
error: 1 errors parsing expression 
(lldb) po self.navigationController; 
nil 
(lldb) po self.navigationItem; 
<UINavigationItem: 0x8997070> 
(lldb) 
(lldb) po self.navigationController.navigationItem.rightBarButtonItem 
error: property 'navigationItem' not found on object of type 'id' 
error: 1 errors parsing expression 

navigationControllernil이며, 우리가 직접 navigationItem를 호출해야 것 같다 : 다음은 결과입니다. 그래서 코드를 변경했지만 다시 작동하지 않습니다. 그래서 이러한 변수를 확인 :

(lldb) po self.navigationItem 
<UINavigationItem: 0x8d789c0> 
(lldb) po self.navigationItem.rightBarButtonItem 
error: property 'rightBarButtonItem' not found on object of type 'id' 
error: 1 errors parsing expression 
(lldb) 

rightbarbuttonitem이없는 것 같다. 그럼 이제 어떻게해야하지?

+1

그 라인에 중단 점을 추가하고 확인하기 위해 콘솔에서'po'를 사용 TabBarController는 ==>NavigationController ==>YourViewController

이 같은 UIBarButtonItem을 설정하려면 만약 'self.navigationController.navigationItem.rightBarButtonItem'이 존재하면. –

+0

나는 지금까지 콘솔과 '포'를 사용하지 않았으며 나는 그들에 익숙하지 않다. 그것이 어떻게 작동하는지 확인하기 위해 검색하겠습니다. –

+0

내 편집을 참조하십시오 –

답변

2

오른쪽 막대 단추 항목을 변경할 수없는 이유는 탭 컨트롤러가 탐색 컨트롤러 스택에만 있기 때문입니다. 보기 제어기는 탭 막대 제어기에만 액세스 할 수 있습니다.

사용자 지정 탐색 모음 단추가 있으려면 UITabBarController에 추가/설정해야합니다.

각보기 컨트롤러마다 다른 UIBarButtons을 갖고 싶다면 위임 방법 tabBarController:didSelectViewController:이 있습니다. 여기에서 선택한보기 컨트롤러를 기반으로 UIBarButtonItem을 변경할 수 있습니다.

+0

uibarbuttoncontroller에 어떻게 추가 할 수 있습니까? barbuttonitems도 허용합니까? –

+0

UIBarButtonController? UITabBarController 클래스에 코드를 추가하기 만하면됩니다. –

0

보기 인 경우 :

self.tabBarController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(doSome)];