2013-06-27 3 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

Move Инициализирующей ваших toolbarItems к инициализатору вы на самом деле вызывающему (initWithTableViewStyle:) и self.navigationController.toolbarHidden = NO; к viewWillAppear, как self.navigationController будет будь то в вашем intializer.

+0

Спасибо, это сработало. –

0

Потому что вы не называете это!

Вы звоните

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

где вы должны называть

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

Насколько я могу судить, initWithNibName не называется. Yoc call initWithStlye.

И даже тогда - в этот момент ваш hvc не является частью иерархии навигации. Значение self.navigationController должно быть nil во время init. Он получает значение, как только он назначается как rootviewcontroller для недавно созданного UINavigationController.