I have a UIPageViewController
, and one of its View Controller
s has a Container View
where its parent View Controller
passes data into it so the container can display dynamic data. I currently have the parent view passing data into the view within the container view with this prepareForSegue
method:
//In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
NSLog(@"CALLED PREPARE FOR SEGUE");
if ([segue.identifier isEqualToString:@"viewEmbed"]) {
//pass data
}
}
However, this prepareForSegue
method is only called once (note my NSLog debugging statement), but I need to pass different data to the child view every time the UIPageViewController
swipes to the parent view. I also noticed that the viewDidLoad
method fires only once in my parent view because the UIPageViewController
retains the state of its pages.
Is there a way to re-instantiate (call viewDidLoad again) the parent view every time it is swiped to from the UIPageViewController
? I'm thinking that would make the prepareForSegue
method fire more than once, which I need it to do. Or am I thinking about this the wrong way and there is a more elegant solution?
Any help or advice would be appreciated. Thanks.
The view did load is only called once as is the segue since your view will only be loaded once. You should do this manually by
UIPageViewController
impelemt
- (void)pageViewController:(UIPageViewController * nonnull)pageViewController willTransitionToViewControllers:(NSArray<UIViewController *> * nonnull)pendingViewControllers
to receive these updatescall a method on you child but not the
viewDidLoad
,viewWillAppear
orviewDidAppear
since there is code that should not executed multiple times. You should copy you current viewDidLoad code from you child into a new method and call this method from the parent when the delegate method is called