问题描述
我知道还有其他几个类似的问题,但我找不到解决我的问题的方法.我使用一个 pageViewController 来显示不同的 ViewControllers.每次 pageViewController 向前移动时,我都会检查 lastPage 的输入.如果它是错误的 pageViewController 应该使用 setViewController 方法返回到该页面.如果没有此方法,一切正常,但如果我尝试使用它,应用程序将崩溃,但出现以下异常:
I know that there are several other questions like this, but i couldn't find a solution for my problem.I use a pageViewController which displays different ViewControllers. Every time the pageViewController moves forward I check the input of the lastPage. If it's wrong the pageViewController should go back to that page by using the setViewController method. Without this method everything works fine but if I try to use it the app crashes with the following exception:
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
}
}
}
正如我已经说过的.我搜索了很多并实施了一些解决方案,但没有任何帮助.谢谢.
As I already said. I searched a lot and implemented some solutions but nothing helped.Thanks.
推荐答案
我遇到了同样的问题,并且能够使用这个答案中的提示解决它https://stackoverflow.com/a/20973822/3757370.只需将 setViewControllers:direction:animated:completion: 代码放在主队列上的 dispatch_async 块中即可为我修复它.对你来说,这看起来像
I ran into the same problem, and was able to solve it using a tip from this answer https://stackoverflow.com/a/20973822/3757370. Simply placing the setViewControllers:direction:animated:completion: code inside of a dispatch_async block on the main queue fixed it for me. For you this would look like
dispatch_async(dispatch_get_main_queue(), ^{
[self.pageViewController setViewControllers:@[ [self.storyboard instantiateViewControllerWithIdentifier:_pageStoryBoardIDs[0]] ]
direction:UIPageViewControllerNavigationDirectionReverse
animated:YES completion:nil];
});
希望有帮助!
这篇关于pageViewController setViewControllers 因“无效参数不满足:[views count] == 3"而崩溃;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!