【问题标题】:How to add button to toolbar using Three20?如何使用 Three20 将按钮添加到工具栏?
【发布时间】:2011-08-22 21:00:12
【问题描述】:

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

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

但是当我启动应用程序时,工具栏中没有按钮! :(

【问题讨论】:

    标签: objective-c uibutton three20 uitoolbar


    【解决方案1】:

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

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

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

    [infoButton release];

    viewWillAppear 方法的底部。

    【讨论】:

      猜你喜欢
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-11
      • 2011-02-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多