【问题标题】:UIPageViewController with dynamic content in childViewControllerUIPageViewController 在 childViewController 中具有动态内容
【发布时间】:2014-05-17 23:13:42
【问题描述】:

我有一个 UIPageViewController,它有三个 childViewController。这些 childViewController 正在显示图表,每 5 秒自动更新一次,使用从网络连接获取的动态数据。

如何在 UIPageViewController 内自动刷新 childViewControllers 的内容?

【问题讨论】:

    标签: ios objective-c cocoa-touch uipageviewcontroller uipagecontrol


    【解决方案1】:

    您可以在 viewDidLoad 中使用计时器,例如:

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

    【讨论】:

    • 谢谢,但我将如何刷新 refreshControllers 方法中的控制器?等式。我在 UIPopoverViewController 中有三个 childViewController,我们可以称它们为 _view1、_view2、_view3。现在我已经用新数据更新了 _view1,但是我如何强制 UIPopoverViewcontroller 重新加载它的 childViews?
    • 检查我的编辑版本,注意self.pageViewController,因为如果你真的在你的pageviewcontroller中,你只会使用self。
    • 非常感谢,到目前为止效果很好,只剩下一个小问题。我确实调用了 setViewControllers:_firstVc、addChildViewController_secondVc、addChildViewController:_thirdVc 来更新 VC。但是当用户将 pageconrolview 移动到 _secondVc 时,触发刷新后 pageControl 将在下次刷新后自动移回 _firstVc。即使 vc 刷新了,我能做些什么来保持当前显示的 vc 显示吗?
    • 您需要跟踪当前的视图控制器:stackoverflow.com/questions/8400870/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-18
    • 1970-01-01
    • 2014-03-06
    • 1970-01-01
    • 2014-02-14
    • 1970-01-01
    相关资源
    最近更新 更多