【问题标题】:hiding or adding a UIBarbuttonitem in tableview在 tableview 中隐藏或添加 UIBarbuttonitem
【发布时间】:2009-08-17 10:12:03
【问题描述】:

我有一个关于在 UIToolbar 上隐藏、删除或添加 UIBarbuttonItem 的问题。

我有一个 UIToolbar 和两个项目。 我希望在工具栏上隐藏一个项目,当我输入第三个 UITableview 时 它会出现。

我已将此代码放入我的 viewDidload

 instruct = [[UIBarButtonItem alloc]

  initWithImage:[UIImage imageNamed:@"b_info.png"] style:UIBarButtonItemStylePlain target:self action:@selector(instruct_clicked:)];

instruct.title =@"instructions";



spacebetween = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

items = [NSMutableArray arrayWithObjects:vorige, spacebetween, aanwijzingen, spacebetween, nil];


[toolbar setItems:items] 

现在我想要的是,在我的程序中的某个时刻,我调用了一个函数,该函数可以将另一个项目添加到工具栏。

这里举例

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

... .. 
... 
... 
//and then something like this 

[items addObject: anotherButton];

[工具栏 setItems:items]

}

我想我可以在 mutableArray 中添加另一个项目,但不幸的是我无济于事。 有没有人有线索或想法。

【问题讨论】:

    标签: iphone objective-c uitableview uitoolbar


    【解决方案1】:

    如果您希望items 成为 NSMutableArray,您必须将其声明为一个。你不能在一个普通的 NSArray 中添加任何东西。

    评论后编辑:您还需要在[items addObject:anotherButton] 之后再次执行[toolbar setItems:items]

    【讨论】:

    • thnx .. ;) 那里也有点草率
    猜你喜欢
    • 1970-01-01
    • 2012-01-23
    • 1970-01-01
    • 2011-12-12
    • 2016-11-24
    • 2016-07-21
    • 1970-01-01
    • 1970-01-01
    • 2013-10-22
    相关资源
    最近更新 更多