5

所以我正在尝试创建一个类似 ibooks 的阅读器,我需要在从 web 服务获取数据后动态更新 UIPageViewController 的内容。由于一系列原因,我必须在开始时实例化它,然后在数据到来时更新它。

我正在这样创建它:

NSDictionary *options =
[NSDictionary dictionaryWithObject:
 [NSNumber numberWithInteger:UIPageViewControllerSpineLocationMin]
                            forKey: UIPageViewControllerOptionSpineLocationKey];

self.pageController = [[UIPageViewController alloc]
                       initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl
                       navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal
                       options: options];

self.pageController.dataSource = self;
self.pageController.delegate = self;

[[self.pageController view] setFrame:[[self view] bounds]];

MovellaContentViewController *initialViewController = [self viewControllerAtIndex:0];

self.controllers = [NSArray arrayWithObject:initialViewController];

[self.pageController setViewControllers:self.controllers
                              direction:UIPageViewControllerNavigationDirectionForward
                               animated:NO
                             completion:nil];

[self addChildViewController:self.pageController];
[[self view] addSubview:[self.pageController view]];
[self.pageController didMoveToParentViewController:self];

然后我就设置self.controllers = newControllersArray;

我正在为 UITableViewController 寻找类似 reloadData 的东西,UIPageViewController 有这样的东西吗?

4

2 回答 2

11

您必须再次将 setViewControllers:direction:animated:completion: 发送到 pageController 并为其提供第一个要显示的视图控制器:

[self.pageController setViewControllers:[NSArray arrayWithObject:
                                            [self viewControllerAtIndex:0]
                                        ]
                              direction:UIPageViewControllerNavigationDirectionForward
                               animated:NO
                             completion:nil];

如果viewControllerAtIndex:不像我最初假设的那样访问self.controllers,它可能应该是

[self.pageController setViewControllers:[NSArray arrayWithObject:
                                            [self.controllers objectAtIndex:0]
                                        ]
                              direction:UIPageViewControllerNavigationDirectionForward
                               animated:NO
                             completion:nil];

反而

于 2012-08-09T14:43:14.967 回答
1

主要问题是 webview 正在拦截所有用户触摸,因此 UiPageViewController 没有调用委托方法。一旦将 webview 设置为忽略用户触摸事件,一切都开始正常工作。

于 2012-08-22T21:59:00.107 回答