推视控制器不工作

时间:2017-01-12 04:37:59

标签: ios objective-c uinavigationcontroller uipageviewcontroller

我在UINavigation中使用UIPageViewUIViewController控制器。我有3个按钮,这是我的代码:

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

当我点击右键并返回此视图控制器时,我的开始按钮的推送视图无效。

1 个答案:

答案 0 :(得分:0)

请检查答案。 iOS - Push viewController from code and storyboard

不要始终初始化故事板,

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

您可以从UtoryBoard本身设置rootViewController。 将initialViewController设置为UINavigationController并将FirstViewController设置为RootViewController。

修改: 对于Push,请使用以下代码,

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

然后回来。如果使用默认的backButton则不需要编写任何代码。 如果使用自定义backButton,

[self.navigationController popViewController];

检查2件事,

  1. 您的故事板标识符是正确的。
  2. 根视图有导航控制器。
  3. 你的StoryBoard应该是这样的, enter image description here