UIButton displaying view but not toggling to pause button
<p>I Have a UIButton and it has multiple actions associated with it </p>

<ol>
<li>To play audio file</li>
<li>Toggle between play pause button</li>
<li>Display views</li>
</ol>

<p>If i comment out the displayViewAction: it is working fine (i.e playing audio file and also toggling to pause button). But if I use the displayViewAction: method it is playing audio file displaying view but before displaying the view it should immediately toggle the state of the pause button, but it is not.</p>

<p>Code bellow for reference:</p>

<p>Code for UIButton:</p>

<pre><code>UIButton *playpauseButton = [UIButton buttonWithType:UIButtonTypeCustom];
[playpauseButton addTarget:self action:@selector(playpauseAction:) forControlEvents:UIControlEventTouchUpInside];
[playpauseButton addTarget:self action:@selector(displayviewsAction:) forControlEvents:UIControlEventTouchUpInside];
playpauseButton.frame = CGRectMake(0, 0, 50, 50);
[playpauseButton setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal];
[playpauseButton setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateSelected];

UIBarButtonItem *playpause = [[UIBarButtonItem alloc] initWithCustomView:playpauseButton];
</code></pre>

<p>Code for Playpause button:</p>

<pre><code>-(void)playpauseAction:(id)sender 
{
  if ([audioPlayer isPlaying]){
      [sender setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal];
      [audioPlayer pause];
  } 
  else {
      [sender setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];
      [audioPlayer play];
  }  
}
</code></pre>

<p>Code for display view action:</p>

<pre><code>- (void)displayviewsAction:(id)sender
{
   self.view = [[[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]]autorelease];
   [self.view setFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];

   PageOneViewController *viewController = [[[PageOneViewController alloc] init]autorelease];
   [self.view addSubview:viewController.view];
}
</code></pre>

<p>Can anyone please advise how I can make it work this way?</p>
