【发布时间】:2015-12-11 09:10:19
【问题描述】:
我的 jumpToPage 逻辑与 PageViewController 有问题。我实现了如下所示的逻辑,它在 iPhone 5S/6/6 Plus 和 iPad 上运行良好......但在 iPhone 5C/5/4S 及以下,我的方法将无法执行,因为 pageIndex 不同......这是我的代码页面跳转:
-(void)gotoPage:(int)index{
SinglePageViewController *viewController = [self viewControllerAtIndex:index];
UIPageViewControllerNavigationDirection direction;
if(_curIndex <= index){
direction = UIPageViewControllerNavigationDirectionForward;
}
else
{
direction = UIPageViewControllerNavigationDirectionReverse;
}
if(_curIndex < index)
{
for (int i = 0; i <= index; i++)
{
if (i == index) {
[self.pageViewController setViewControllers:@[viewController]
direction:direction
animated:YES
completion:nil];
}
else
{
[self.pageViewController setViewControllers:@[[self viewControllerAtIndex:i]]
direction:direction
animated:NO
completion:nil];
}
}
}
else
{
for (int i = _curIndex; i >= index; i--)
{
if (i == index) {
[self.pageViewController setViewControllers:@[viewController]
direction:direction
animated:YES
completion:nil];
}
else
{
[self.pageViewController setViewControllers:@[[self viewControllerAtIndex:i]]
direction:direction
animated:NO
completion:nil];
}
}
}
_curIndex = index;
}
好的,这个逻辑有效...这是检查当前 pageIndex 并调用此 gotoPage 方法的方法:
-(void)refreshPagesWith:(Articles *)article{
NSUInteger pageIndex = -1;
for (int i = 0; i < self.pages.count; i ++) {
Pages *page = [self.pages objectAtIndex:i];
if (page.articleID == article.articleID) {
pageIndex = i;
break;
}
}
if (pageIndex != -1) {
NSLog(@"THEORY: Maybe pageIndex IS -1 on iPhone 5 and below!!!");
[self gotoPage:pageIndex];
}
好的,这就是问题所在...在 iPhone 5S/6/6Plus 上 pageIndex 不是 -1,并且该方法成功执行并且一切正常...但是由于某种原因,在 iPhone 5C 及以下版本上,pageIndex 始终为 - 1 和方法不会执行...如果我尝试提前 [self gotoPage:pageIndex];应用程序崩溃......谁能帮我改变我的逻辑?!?最好的问候,
【问题讨论】:
标签: ios objective-c iphone xcode