开发者

initWithBarButtonItem change from UIBarButtonSystemItemPause to UIBarButtonSystemItemPlay?

My application has a UIBarButtonI开发者_开发知识库tem 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;
 }


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜