views:

1528

answers:

1

Hello all ,

I have a question concerning hiding ,removing or adding a UIBarbuttonItem on UIToolbar.

I have a UIToolbar and two items. I wish to hide an item on the toolbar and when I enter for example third UITableview it will appear.

I've put this code in my 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]

Now what i would like is that at one moment in my program I call a function which either adds another item to the toolbar.

Example here

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

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

[items addObject: anotherButton];

[toolbar setItems:items]

}

I figured I could just add another item to my mutableArray but unfortunately for me to no avail. Does anyone have a clue or an idea.

+1  A: 

If you want items to be an NSMutableArray, you're going to have to declare it as one. You can't add anything to a plain ol' NSArray.

Edit after comment: you'll also need to do [toolbar setItems:items] again after [items addObject:anotherButton].

Meredith L. Patterson
oh that's right .. but it was a typo ;) , I corrected it now
thnx .. ;) bit sloppy there too
aha gotcha ... ...