2013-06-27 4 views
0
여기

내가의 도구 모음을 표시하려고 내 탐색 컨트롤러의 루트 뷰 컨트롤러의 초기화 방법 :왜이 UIToolBar가 나타나지 않습니까?

-(id) initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{ 
    self = [super initWithNibName:nil bundle:nil]; 
    if(self){ 
     //GUI implementation 
     self.navigationController.toolbarHidden = NO; 
     UIBarButtonItem *flexiableItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace 
                         target:self 
                         action:nil]; 
     UIBarButtonItem *item1 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemRefresh 
                       target:self 
                       action:nil]; 
     self.toolbarItems = [NSArray arrayWithObjects:flexiableItem, item1, nil]; 

     UIBarButtonItem* addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd 
                        target:self 
                        action:@selector(addEmployee)]; 

     self.navigationItem.rightBarButtonItem = addButton; 
     self.navigationItem.leftBarButtonItem = self.editButtonItem; 
    } 
    return self; 
} 

을 여기에 애플 대리자 내 대표 application:DidFinishLaunching 방법 :

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 
    // Override point for customization after application launch. 
    BOHomeViewController* hvc = [[BOHomeViewController alloc] initWithStyle:UITableViewStylePlain]; 

    UINavigationController* navbar = [[UINavigationController alloc] initWithRootViewController:hvc]; 
    [self.window setRootViewController:navbar]; 

    self.window.backgroundColor = [UIColor whiteColor]; 
    [self.window makeKeyAndVisible]; 
    return YES; 
} 

도구 모음이 전혀 표시되지 않습니다. 누군가 제가 잘못하고있는 것을 지적 할 수 있습니까? 매우 감사.

답변

0

이동 당신이 실제로 (initWithTableViewStyle:)를 호출하고있는 이니셜로 toolbarItems의 초기화 및 self.navigationController.toolbarHidden = NO;를 호출 할 위치

당신은

BOHomeViewController* hvc = [[BOHomeViewController alloc] initWithStyle:UITableViewStylePlain]; 

를 호출하는 것입니다 귀하의 초기 과정에서 아무 것도하지 마십시오.

+0

감사합니다. –

0

전화하지 않으므로! 당신이 self.navigationController로 viewWillAppear에

BOHomeViewController* hvc = [[BOHomeViewController alloc] initWithNibName:<"Some Name"> bundle:<"Some Bundle">]; 
0

내가 알 수있는 한, initWithNibName은 호출되지 않습니다. Yoc 전화 : initWithStlye.

그리고 그 시점에서 hvc는 탐색 계층의 일부가 아닙니다. 의미 self.navigationController init 동안 nil해야합니다. 나중에 새로 생성 된 UINavigationController에 rootviewcontroller로 지정되면 즉시 값을 얻습니다.

관련 문제