새 창 기반 응용 프로그램과 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;
}
내가 뭘 잘못하고 있니?
당신이뿐만 아니라 UIViewController 하위의 제목과 rightBarButton을 설정하려고 했습니까? '-viewDidLoad'가이 작업을 수행하기에 적합한 장소로 보입니다. 또한 UINavigationController가 UIViewController 하위 클래스의'-viewDidLoad' 내부에 nil이 아닌지 확인하십시오. –