1

I'm using UINavigation and UIPageView controller in a UIViewController. I have 3 buttons and here is my code :

- (IBAction)StartButtonClicked:(id)sender {
     NSLog(@"start button pressed");
     [_Timer invalidate];
     _Timer = nil;

     dispatch_async(dispatch_get_main_queue(), ^{
         UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
         CardViewController* controller = [storyboard instantiateViewControllerWithIdentifier:@"CardViewController"];
         [self.navigationController pushViewController:controller animated:NO];
    }
}

- (void)pageViewController {
    self.pvc = [[UIPageViewController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStyleScroll navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:nil];

    self.pvc.view.frame = self.view.bounds;
    [self.view addSubview:self.pvc.view];
    [self.pvc setViewControllers:@[[viewControllerArray1 objectAtIndex:0]] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
}

- (IBAction)rightButtonPressed:(id)sender {
    [self pageViewController];
    [self.pvc setViewControllers:@[[viewControllerArray1 objectAtIndex:1]] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:nil];
}

- (IBAction)leftButtonPressed:(id)sender {
     [self pageViewController];
     [self.pvc setViewControllers:@[[viewControllerArray1 objectAtIndex:2]] direction:UIPageViewControllerNavigationDirectionReverse animated:YES completion:nil];
}

When I click on right button and came back to this view controller my start button's push view not working.

Arasuvel
  • 2,971
  • 1
  • 25
  • 40
Sumi
  • 39
  • 1
  • 10

1 Answers1

0

Please check the answer . iOS - Push viewController from code and storyboard

Don't initialize Storyboard always,

UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

You can set the rootViewController from the UtoryBoard itself. Set initialViewController as a UINavigationController and Set the FirstViewController as RootViewController.

Edit : For Push use the below code,

 CardViewController* controller = [storyboard instantiateViewControllerWithIdentifier:@"CardViewController"];
    [self.navigationController pushViewController:controller animated:NO];

and Back. If use the default backButton not need to write any code. If use are using custom backButton,

[self.navigationController popViewController];

Check 2 things,

  1. Your storyboard identifier is correct.
  2. The root view have navigation Controller.

Your StoryBoard should be like this, enter image description here

Community
  • 1
  • 1
Vineesh TP
  • 7,755
  • 12
  • 66
  • 130
  • In 'StartButtonClicked' you are initializing the storyBorad again. Not need to set storyBoard again. Set via main.storyBoard itself. – Vineesh TP Jan 12 '17 at 05:13
  • now i removed that line.. click on left/right button and navigate to other view controller and then click back button from that view and come back here (start button not working but left/right button working).. this is the scenario. – Sumi Jan 12 '17 at 05:14
  • for push use the code: CardViewController* controller = [storyboard instantiateViewControllerWithIdentifier:@"CardViewController"]; [self.navigationController pushViewController:controller animated:NO]; and for back use [self.navigationController popViewController]; – Vineesh TP Jan 12 '17 at 06:04