Removing a view controller from UIPageViewController

前端 未结 12 2502
梦谈多话
梦谈多话 2020-11-28 19:22

It\'s odd that there\'s no straightforward way to do this. Consider the following scenario:

  1. You have a page view controller with 1 page.
  2. Add another p
12条回答
  •  遥遥无期
    2020-11-28 19:54

    NSMutableArray *mArray = [[NSMutableArray alloc] initWithArray:self.userArray];
    [mArray removeObject:userToBlock];
    self.userArray = mArray;
    
    UIViewController *startingViewController = [self viewControllerAtIndex:atIndex-1];
    NSArray *viewControllers = @[startingViewController];
    [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionReverse animated:NO completion:nil];
    

    I didn't quite have time to read through the above comments but this worked for me. Basically I remove the data (in my case a user) and then move to the page before it. Works like a charm. Hope this helps those looking for a quick fix.

提交回复
热议问题