簡體   English   中英

UIPageViewController NSInternalInconsistencyException

[英]UIPageViewController NSInternalInconsistencyException

我正在開發一個簡單的UIPageViewController ,它有兩個頁面。 每個頁面都從不同的ViewController加載,它們具有特定的xib文件,名為PViewControllerTViewController

對於PViewController ,有三個不同的視圖,我們稱它們為ABC 當應用程序啟動時, PViewController成功出現,我可以向左滑動以查看TViewController ,也沒有問題。 但是,當我在PViewController並且作為對事件的響應時,我將當前視圖A更改為另一個視圖B ,然后向左滑動以轉到TViewController ,我收到以下異常並且應用程序終止:

*** Assertion failure in -[_UIQueuingScrollView _setWrappedViewAtIndex:withView:], /SourceCache/UIKit_Sim/UIKit-2935.137/_UIQueuingScrollView.m:338
2014-07-10 13:57:23.389 ***** [2012:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unexpected subviews'
*** First throw call stack:
(
    0   CoreFoundation                      0x01fde1e4 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x01c418e5 objc_exception_throw + 44
    2   CoreFoundation                      0x01fde048 +[NSException raise:format:arguments:] + 136
    3   Foundation                          0x018214de -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116
    4   UIKit                               0x00f3cc14 -[_UIQueuingScrollView _setWrappedViewAtIndex:withView:] + 261
    5   UIKit                               0x00f3d248 -[_UIQueuingScrollView _replaceViews:updatingContents:adjustContentInsets:animated:] + 812
    6   UIKit                               0x00f3d690 -[_UIQueuingScrollView _viewAtIndex:loadingIfNecessary:updatingContents:animated:] + 421
    7   UIKit                               0x00f40c65 __54-[_UIQueuingScrollView _didScrollWithAnimation:force:]_block_invoke + 110
    8   UIKit                               0x00f408de -[_UIQueuingScrollView _didScrollWithAnimation:force:] + 579
    9   UIKit                               0x00f3c452 -[_UIQueuingScrollView layoutSubviews] + 186
    10  UIKit                               0x00970964 -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 355
    11  libobjc.A.dylib                     0x01c5382b -[NSObject performSelector:withObject:] + 70
    12  QuartzCore                          0x04be445a -[CALayer layoutSublayers] + 148
    13  QuartzCore                          0x04bd8244 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380
    14  QuartzCore                          0x04bd80b0 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 26
    15  QuartzCore                          0x04b3e7fa _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 294
    16  QuartzCore                          0x04b3fb85 _ZN2CA11Transaction6commitEv + 393
    17  QuartzCore                          0x04b40258 _ZN2CA11Transaction17observer_callbackEP19__CFRunLoopObservermPv + 92
    18  CoreFoundation                      0x01fa636e __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 30
    19  CoreFoundation                      0x01fa62bf __CFRunLoopDoObservers + 399
    20  CoreFoundation                      0x01f839eb CFRunLoopRunSpecific + 491
    21  CoreFoundation                      0x01f837eb CFRunLoopRunInMode + 123
    22  GraphicsServices                    0x030285ee GSEventRunModal + 192
    23  GraphicsServices                    0x0302842b GSEventRun + 104
    24  UIKit                               0x00901f9b UIApplicationMain + 1225
    25  *******                             0x000239fd main + 141
    26  libdyld.dylib                       0x02cc1701 start + 1
    27  ???                                 0x00000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

這是我為 UIPageViewController 實現的協議方法:

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController
{
    UIViewController *vc;

    if(self.index==1) {
        vc = (PViewController *)[[PViewController alloc] initWithNibName:@"PViewController" bundle:nil];
    }
    self.index--;


    return vc;
}

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController {
    UIViewController *vc;



    if(self.index==0)
        vc = (TViewController *)[[TViewController alloc] initWithNibName:@"TViewController" bundle:nil];

    self.index++;


    return vc;
} //The exception occurs exactly when the app reaches this point.

這就是我在視圖控制器中切換視圖的方式,簡單地說:

self.view = self.B; 

問題:

我無法追蹤問題。 我不知道在哪里捕獲這個異常或導致它的原因是什么?

在使用啟動時傳遞的以下參數時,我偶然發現了同樣的錯誤:

-UIViewShowAlignmentRects YES

在浪費了 2 天試圖在我的 UIPageViewController 中查找錯誤之后,結果是在禁用 XCode 生成的黃色矩形包裝器后,NSInternalConsistencyException 消失了。

想通了(至少我的問題是什么) - 你不應該直接設置 UIViewController 的 self.view,而是使用 self.view.addSubview(viewA) 然后使用

UIView.transitionFromView(self.viewA, toView: self.viewB, duration: 0.5, options: UIViewAnimationOptions.TransitionFlipFromLeft, completion: nil)

就我而言,這發生在我嘗試導航到另一個視圖控制器中的下一個頁面視圖控制器時,該視圖控制器顯示為 modal

希望這可以幫助其他人。

我在 Storyboard 中有一個“UIPageViewController”,從其中一個頁面,我試圖展示新的“UINavigationController”,並附加“Rootviewcontroller”,它位於單獨的 xib 中。

當我刪除 xib 並將此視圖控制器作為獨立的故事板放置時,它就像一個魅力。

所以我認為問題在於,如果兩個容器視圖都在同一個故事板中,那么它不會給出任何異常或錯誤。

let listView = String(describing: ListViewController.self)
let listViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: listView)
let navigationController = UINavigationController(rootViewController: listViewController)
self.present(navigationController, animated: true, completion: nil)

我通過改變方向 .forward,到 .reverse 來解決這個崩潰

pageViewController?.setViewControllers([viewController], direction: direction, animated: true)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM