I'm trying various ways of changing a UIBarButtonItem's image once it has been pressed, without any luck.
// bookmarkButton is a property linked up in IB
-(IBAction)bookmarkButtonTapped:(id)sender
{
NSLog(@"this action triggers");
// attempt 1
UIBarButtonItem* aBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"bookmarkdelete.png"] style:UIBarButtonItemStylePlain target:self action:@selector(bookmarkButtonTapped:)];
bookmarkButton = aBarButtonItem;
[aBarButtonItem release];
// attempt 2
bookmarkButton.image = [UIImage imageNamed:@"bookmarkdelete.png"];
}
Is there another way to do this?
The toolbar contains an array - items - as a property. So after setting up the toolbar as an IBOutlet property, I had to insert a new button into that array.. like this:
NSMutableArray *items = [[NSMutableArray alloc] initWithArray:self.toolBar.items];
UIBarButtonItem *newButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"newButton.png"] style:UIBarButtonItemStylePlain target:self action:@selector(buttonTapped:)];
[items replaceObjectAtIndex:0 withObject:newButton];
self.toolBar.items = items;
[newButton release];
[items release];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With