如何使用Three20向工具栏添加按钮?

时间:2011-08-22 21:00:13

标签: objective-c uibutton three20 uitoolbar

我正在尝试使用此按钮向工具栏添加按钮:

- (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];
}

但是当我开始申请时,工具栏中没有按钮! :(

1 个答案:

答案 0 :(得分:2)

不要设置导航控制器toolBarItems属性,而是尝试在当前显示的视图控制器中设置它,如下所示:

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

同时将infoButton添加到toolBarItems将自动保留它。所以记得放置

[infoButton release];

位于viewWillAppear方法的底部。