iOS6中的UIPageViewController [英] UIPageViewController in iOS6
问题描述
在iOS6中的方法 viewControllerAfterViewController 和 viewControllerBeforeViewController 如果我返回nil(当我在第一页或最后一页时阻止页面导航)应用程序崩溃例外:
In iOS6 in the methods viewControllerAfterViewController and viewControllerBeforeViewController if I return nil (for block the page navigation when I am in the first or last page) the app crash with this exception:
'提供的视图控制器数量(0)与请求的转换所需的数量(1)不匹配'
'The number of view controllers provided (0) doesn't match the number required (1) for the requested transition'
在iOS5中一切正常。
In iOS5 all works good.
推荐答案
我遇到了同样的问题。我发现原因是在UIPageViewController的UIPanGestureRecognizer上替换了委托,这是一个禁忌。平移手势识别器正在调用一个未记录的方法_gestureRecognizerShouldBegin :(注意前导下划线)UIPageViewController实现并显然依赖于正常工作(读取:not-crash)。我最终在我的类中实现了respondsToSelector:和forwardingTargetForSelector:它使用UIPageViewController将未记录的委托方法传递给UIPageViewController,而没有特别命名它(几乎肯定会让我获得应用商店评论拒绝)。
I had the same issue. I found that the cause was replacing the delegate on the UIPanGestureRecognizer of the UIPageViewController, a no-no really. The pan gesture recognizer was calling an undocumented method _gestureRecognizerShouldBegin: (note the leading underscore) that UIPageViewController implements and apparently relies upon to work properly (read: not-crash). I ended up implementing respondsToSelector: and forwardingTargetForSelector: in my class that uses the UIPageViewController to pass the undocumented delegate method on to the UIPageViewController without specifically naming it (and almost certainly earning me an app store review rejection).
-(BOOL)respondsToSelector:(SEL)aSelector {
if ([super respondsToSelector:aSelector])
return YES;
else if ([self.pageViewController respondsToSelector:aSelector])
return YES;
else
return NO;
}
- (id)forwardingTargetForSelector:(SEL)aSelector {
if ([super respondsToSelector:aSelector]) {
return nil;
} else if ([self.pageViewController respondsToSelector:aSelector]) {
return self.pageViewController;
}
return nil;
}
我的长期解决方案是重新使用UIPageViewController,这样我就不会不需要取代手势识别器代表。
My longer term solution will be to rework the use of UIPageViewController such that I don't need to displace the gesture recognizer delegates.
这篇关于iOS6中的UIPageViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!