0

의 특정보기에서 내 제목으로 rightbarbuttonitem을 추가하는 방법, tabbarcontroller의 특정보기에서 rightbarbuttontiem을 어떻게 추가합니까?tabbarcontroller

저는 storyarboard를 사용하여 tabarcontroller를 만듭니다.

내가이 시도하지만 항목은

UIBarButtonItem *settingButton = [[UIBarButtonItem alloc] 
            initWithImage:[UIImage imageNamed:@"gear.png"] 
            style:UIBarButtonItemStylePlain 
            target:self 
            action:@selector(pushToSetting)]; 

//BarButtonItem *settingButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject)]; 
self.navigationItem.rightBarButtonItem = settingButton; 
+0

UITabBarController와 UINavigationController가 혼합되어 있습니다. – Till

답변

1

당신이있는 navigationController를 사용하고 표시되지 않습니다? 그렇다면 코드가 작동해야합니다. UINavigationBar 만 사용하는 경우 UINavigationBar의 items 속성을 설정해야합니다. rightbuttonitem을 얻지 못했기 때문에 UINavigationBar를 사용하고 있다고 가정합니다. 이 코드는 작동해야합니다 :

UIBarButtonItem *settingButton = [[UIBarButtonItem alloc] initWithTitle:@"Settings" style:UIBarButtonItemStylePlain target:self action:nil]; 
UINavigationItem *navItem = [[UINavigationItem alloc] initWithTitle:@"Test"]; 
navItem.rightBarButtonItem = settingButton; 
NSArray *navItems = [NSArray arrayWithObject:navItem]; 
[self.navBar setItems:navItems]; 

이제 rightbarbuttonitem이 있어야합니다. 여기에서 navBar는 UINavigationBar 콘센트입니다. 또한 팝업 및 이러한 방법을 사용 UINavigationBar에 탐색 항목을 밀어 수 있습니다

  • (무효) pushNavigationItem : (UINavigationItem *) 항목 애니메이션 : (BOOL)이 애니메이션;
  • (UINavigationItem *) popNavigationItemAnimated : (BOOL) animated;
관련 문제