我有一个关于在UIToolbar上隐藏、删除或添加UIBarbuttonItem的问题。
我有一个UIToolbar和两个项目。我希望隐藏工具栏上的一个项目,例如,当我输入third 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];工具栏集项目:项目
}我想我可以向我的mutableArray添加另一个项目,但不幸的是,对我来说无济于事。有没有人有线索或者想法。
发布于 2009-08-17 10:16:36
如果你想让items成为一个NSMutableArray,你必须将它声明为一个。你不能在一个普通的NSArray中添加任何东西。
注释后编辑:在[items addObject:anotherButton]之后,您还需要再次执行[toolbar setItems:items]。
https://stackoverflow.com/questions/1287160
复制相似问题