【问题标题】:Different pageIndex with different iPhone devices不同 iPhone 设备的不同 pageIndex
【发布时间】: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


    【解决方案1】:

    好吧,看来我自己解决了这个问题,我只是想让有同样问题的人知道我做了什么......

    由于某种原因,这行代码:if (page.articleID == article.articleID) 不比较 iPhone 5/4S 模拟器中的对象...我只是更改为if ([page.articleID isEqual: article.articleID]),现在它适用于所有设备...

    注意==比较指针,而isEqual:比较对象...我希望以后这个答案能帮助遇到同样问题的每个人。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-10
      • 2013-05-17
      相关资源
      最近更新 更多