UIPageViewController with different ViewControllers, right way?

后端 未结 4 1272
半阙折子戏
半阙折子戏 2021-01-03 02:25

Basically, I have a Table View Controller and a normal View Controller, I want to make it so that I can swipe between the view controllers like on the home screen of app (ob

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-03 03:23

    Finally done it, didn't have to add any properties to the different classes. Just tested the class. Heres the code:

    -(UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
    {
        if ([viewController isKindOfClass:[MainTableViewController class]]) {
            MainPostController *pvc = [self.storyboard instantiateViewControllerWithIdentifier:@"MainPostController"];
            return  pvc;
    
        }
    
        else return nil;
    
    }
    
    
    -(UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
    {
    
        if ([viewController isKindOfClass:[MainPostController class]]) {
            MainTableViewController *tvc = [self.storyboard instantiateViewControllerWithIdentifier:@"MainTableViewController"];
            return tvc;
    
        }
        else return nil;
    }
    

    Should be easy to add more view controllers as i just need to add else if statements to test them. The main problem solver was the method isKindOfClass:

    Thanks for your reply guys!

提交回复
热议问题