1

새 창 기반 응용 프로그램과 UIViewController를 서브 클래 싱하는 RootViewController를 만들었습니다. AppDelegate에서 UINavigationController를 만들었고 UINavigationController의 뷰를 창에 추가하면 맨 위에 탐색 모음이 보입니다. 그러나 탐색 모음에 단추를 추가 할 수 없습니다. 컴파일 오류는 없지만 단추 (및 제목)는 표시되지 않습니다. 코드는 다음과 같습니다.BarButtonItem이 표시되지 않습니다.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

    RootViewController * rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil]; 
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController]; 

    UIBarButtonItem *next = [[UIBarButtonItem alloc] initWithTitle:@"Next" style:UIBarButtonItemStyleDone target:nil action:nil]; 
    navigationController.title = @"Foo"; 

    navigationController.navigationItem.rightBarButtonItem = next; 

    [self.window addSubview:navigationController.view]; 

    // Override point for customization after application launch. 
    [self.window makeKeyAndVisible]; 
    return YES; 


} 

내가 뭘 잘못하고 있니?

+0

당신이뿐만 아니라 UIViewController 하위의 제목과 rightBarButton을 설정하려고 했습니까? '-viewDidLoad'가이 작업을 수행하기에 적합한 장소로 보입니다. 또한 UINavigationController가 UIViewController 하위 클래스의'-viewDidLoad' 내부에 nil이 아닌지 확인하십시오. –

답변

0

변경이이에

navigationController.navigationItem.rightBarButtonItem = next; 

:

rootViewController.navigationItem.rightBarButtonItem = next; 
0

5 월 스타일 일 수 있습니다. 편집 모드에서만 사용되는 UIBarButtonItemStyleDone이 예입니다. 루트 컨트롤러 또는 하위보기 컨트롤러에있는 경우 self.editing = YES를 호출 할 수 있지만 AppDelegate에서는 실행할 수 없습니다.

관련 문제