Question

I am trying to alter the visible buttons on the toolbar depending on the state of the table view. Is this possible?

To add more detail: I currently have a list of exercises in a table view. There is a toolbar at the bottom with a button on it "new" allowing the user to create a new exercise. When the user clicks "edit" in the top right the view goes into editing mode and I want them to be able to delete exercises using multiple selection by clicking a now unhidden "delete" button in the toolbar. At this point I am trying to make the "new" button disappear and leave only the "delete" button.

I can find lots of answers of how to add toolbars and add buttons to them but none seem to be dealing with this once the view has loaded.

I have thought about having two different toolbars with the separate buttons on each and then switching which is hidden and which is visible but this will lead to other problems so I am exploring whether there is an easy way to only hide the added buttons.

No correct solution

OTHER TIPS

Its really easy. Lets First look how to create a UIToolbar then addd items to it and then change them during run time

self.MNToolbar=[[UIToolbar alloc] init];

self.addButton=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(importPhotos:)];

self.flexibleSpace=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];

self.MNToolbar.items=[[NSArray alloc] initWithObjects:flexibleSpace, addButton, flexibleSpace, nil];

[self.view addSubView:self.MNToolbar];
// don't forget to set the bounds too

This is how to create it.

Ok now lets see how to alter it during runtime

self.deleteButton=[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(deletePhotos:)];

self.MNToolbar.items=[[NSArray alloc] initWithObjects:self.deleteButton, nil];

I hope you get the point. If you have any questions let me know.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top