views:

293

answers:

1

My application has a UIBarButtonItem with a UIBarButtonItemPause icon in the upper right corner of the screen on a UINavigationBar. I'm looking to have it so that when I press the button it changes the icon to a play button, and back to a pause button when it is unpaused (similar to the way in which iTunes, Quicktime, or iPhone's integrated media player does when pressing the play/pause button. Is it possible for me to just change the icon or would it be necessary to create a new button each time and place it on the bar for that to happen? The code that is triggered by the pressing of the button can be found here:

- (IBAction)pauseapp:(UIBarButtonItem *)sender
{
 if(paused==TRUE)
 {
  paused=FALSE;
  [pause initWithBarButtonSystemItem:(UIBarButtonSystemItemPause) target:self action:NULL];
  return;
 }
 else if(paused==FALSE)
 {
  paused=TRUE;
  [pause initWithBarButtonSystemItem:(UIBarButtonSystemItemPlay) target:self action:NULL];
  return;
 }
A: 

You have to create a new button each time; you should never call initXXX on an object more than one time (right after alloc).

Ben Gottlieb