加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xcode – pageViewController setViewControllers崩溃与“无效参

发布时间:2020-12-15 02:00:24 所属栏目:百科 来源:网络整理
导读:我知道这里还有其他几个问题,但是我找不到解决问题的办法。 我使用一个pageViewController来显示不同的ViewController。每次pageViewController向前移动时,我检查lastPage的输入。如果这是错误的,pageViewController应该通过使用setViewController方法返
我知道这里还有其他几个问题,但是我找不到解决问题的办法。
我使用一个pageViewController来显示不同的ViewController。每次pageViewController向前移动时,我检查lastPage的输入。如果这是错误的,pageViewController应该通过使用setViewController方法返回到该页面。没有这种方法一切都可以正常工作,但如果我尝试使用它,应用程序崩溃与以下异常:

19:48:25.596 Phook[23579:60b] *** Assertion failure in -[_UIQueuingScrollView _replaceViews:updatingContents:adjustContentInsets:animated:],/SourceCache/UIKit_Sim/UIKit-2935.137/_UIQueuingScrollView.m:383  
2014-06-02 19:48:25.600 Phook[23579:60b] *** Terminating app due to uncaught   exception 'NSInternalInconsistencyException',reason: 'Invalid parameter not satisfying:   [views count] == 3'

这是我的代码:

- (void)pageViewController:(UIPageViewController *)pageViewController didFinishAnimating:(BOOL)finished
   previousViewControllers:(NSArray *)previousViewControllers transitionCompleted:(BOOL)completed
{
    if (completed && finished)
    {

        RegisterUserPageContent* lastPage = (RegisterUserPageContent*)previousViewControllers[ previousViewControllers.count-1];
        int lastIndex   = lastPage.pageIndex;
        int newIndex    = ((RegisterUserPageContent*)[self.pageViewController.viewControllers objectAtIndex:0]).pageIndex;

        if (newIndex > lastIndex)
        {   // Moved Forward
            if(!lastPage.testInput)
            {
                [self.pageViewController setViewControllers:@[ [self.storyboard instantiateViewControllerWithIdentifier:_pageStoryBoardIDs[0]] ]
                                         direction:UIPageViewControllerNavigationDirectionReverse
                                         animated:YES completion:nil];


            }
        }
        else
        {   // Moved Reverse

        }
    }
}

正如我已经说过的我搜索了很多,并实施了一些解决方案,但没有任何帮助。
谢谢。

解决方法

我遇到同样的问题,并能够使用这个答案 http://stackoverflow.com/a/20973822/3757370的提示来解决它。只需放置setViewController:direction:animated:completion:主队列中的dispatch_async块中的代码为我修复它。对你来说,这样会像

dispatch_async(dispatch_get_main_queue(),^{
    [self.pageViewController setViewControllers:@[ [self.storyboard instantiateViewControllerWithIdentifier:_pageStoryBoardIDs[0]] ]
                                     direction:UIPageViewControllerNavigationDirectionReverse
                                     animated:YES completion:nil];
});

希望有帮助!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读