所以我正在尝试创建一个类似ibooks的阅读器,我需要在从webservice获取数据后动态更新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有这样的东西吗?
答案 0 :(得分:11)
你必须再次向setController发送setViewControllers:direction:animated:completion :. 并给它第一个视图控制器来显示:
[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];
代替
答案 1 :(得分:1)
主要问题是webview拦截了所有用户触摸,因此UiPageViewController没有调用委托方法。将webview设置为忽略用户触摸事件后,一切都开始正常工作。