0

I have a UIPageViewController which has three childViewControllers. Those childViewControllers are disyplaying charts with are automatically updated each 5 seconds with dynamic data feteched from a network connection.

How do I automatically refresh the content of the childViewControllers inside the UIPageViewController?

1 Answers1

1

You can use the timer in the viewDidLoad, e.g. :

- (void)viewDidLoad {
    [super viewDidLoad];
    [NSTimer scheduledTimerWithTimeInterval:5.0f target:self selector:@selector(refreshControllers) userInfo:nil repeats:YES];
    //..
}

- (void)refreshControllers {
    //perform refreshing
    //when you got your _view1, _view2 etc..
    NSArray *viewControllers = @[_view1, _view2, _view3];
    [self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil];
}
sunshinejr
  • 4,834
  • 2
  • 22
  • 32
  • Thanks, but how would i refresh the controllers inside the refreshControllers method? eq. i have three childViewControllers in UIPopoverViewController lets call them _view1, _view2, _view3. Now i have updated _view1 with new data, but how do i force the UIPopoverViewcontroller to reload its childViews? –  May 18 '14 at 11:05
  • Check my edited version, watchout for self.pageViewController, because if you actually are in your pageviewcontroller you would use only self. – sunshinejr May 18 '14 at 11:29
  • Thank you very much, works great so far only one little issue left. I do call setViewControllers:_firstVc, addChildViewController_secondVc, addChildViewController:_thirdVc which updates the VCs now. But when the user moves the pageconrolview to the _secondVc, after the refresh is triggered the pageControl will move automatically back to _firstVc after the next refresh. Is there anything i can do to keep the currently displayed vc displayed even if the vc's did refresh? –  May 18 '14 at 11:39
  • You'll need to keep track of the current view controller: http://stackoverflow.com/questions/8400870/uipageviewcontroller-return-the-current-visible-view – sunshinejr May 18 '14 at 15:06