Button not displayed


I have added multiple actions to one button

  1. Play audiofile
  2. Display array of views

Button is playing audiofile but not displaying views.

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];

Play Pause Action coding



  ([audioPlayer isPlaying]){

 [sender setImage:[UIImage imageNamed:@"play.png"] forState:UIControlStateNormal];

      [audioPlayer pause];

  } else {

 [sender setImage:[UIImage imageNamed:@"pause.png"] forState:UIControlStateNormal];

      [audioPlayer play];



DisplayviewsAction coding

- (void)displayviewsAction:(id)sender

CGRect pageViewRect = self.view.bounds;

pageViewRect = CGRectInset(pageViewRect, 30.0, 30.0);

self.pageViewController.view.frame = pageViewRect;

// Configure the page view controller
   UIPageViewController *pageViewController = [[[UIPageViewController alloc]   initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil]autorelease];

NSArray *viewControllers = [NSArray arrayWithObject:pageViewController]; 

[self.pageViewController setViewControllers:viewControllers

[self.view addSubview:self.pageViewController.view];


Any advice what i m missing in the code or doing wrong.

Thanks for help.

Here are some minor corrections you should make - they may not all help with the problem, but you never know.

Add a completion block here:

[self.pageViewController setViewControllers:viewControllers

I don't remember for sure, but I think setViewControllers is done asynchronously - nothing cannot be added until after the completion handler is done. To add the block, you simply put a ^ and a block of code in (like a normal method):

[self.pageViewController setViewControllers:viewControllers
   // your code here.

This may fix the problem, but I cannot be sure until I can get back to my computer.

You should also put an NSLog at the beginning of every method, at least until you are done debugging. That way, you always know what is being called and what isn't. If it is not called, try removing the autorelease from the pageViewController - it may be released because it isn't being used.