defmthd
defmthd

Reputation: 153

How to add button to toolbar using Three20?

I'm trying to use this to add button to toolbar:

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    [self.navigationController setToolbarHidden:NO animated:NO];
    self.navigationController.toolbar.translucent = YES;
    self.navigationController.toolbar.barStyle    = UIBarStyleBlack;

    UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    button.frame = CGRectMake(0.0, 0.0, 10.0, 10.0);

    UIBarButtonItem *infoButton = [[UIBarButtonItem alloc] initWithCustomView:button];

    NSMutableArray *a = [NSMutableArray arrayWithObject:infoButton];

    [self.navigationController setToolbarItems:a];
}

But there is no button in toolbar when I started application! :(

Upvotes: 2

Views: 468

Answers (1)

ms83
ms83

Reputation: 1814

Instead of setting the navigation controllers toolBarItems property try setting it in the currently displayed view controller like so:

[self setToolbarItems:[NSArray arrayWithObjects:infoButton, nil]];

Also adding infoButton to the toolBarItems will automatically retain it. So remember to place

[infoButton release];

at the bottom of your viewWillAppear method.

Upvotes: 2

Related Questions