2013-06-27 129 views
0

这里是我的导航控制器的根视图控制器,我想显示在工具栏上的init方法:为什么不会出现这个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

移动你toolbarItems的初始化到你实际上调用(initWithTableViewStyle:)初始化和self.navigationController.toolbarHidden = NO;到viewWillAppear中为self.navigationController会在你的初始者中无效。

+0

谢谢,这工作。 –

0

因为你不叫它!

要调用

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

,你应该叫

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

据我所知,initWithNibName没有叫。优酷电话initWithStlye

即使在那时 - 您的hvc不是导航层级的一部分。在init中,self.navigationController的含义应该为零。只要将它作为rootviewcontroller分配给后来新创建的UINavigationController,它就会获得值。

相关问题