当我运行我的应用程序时,我注意到setViewController
方法会导致内存链接并导致我的应用程序崩溃。我已经在这个问题上工作了几个小时,并尝试在网上查找,并找到一个{{ 3}},其中提到将setViewController
方法放在dispatch_async(dispatch_get_main_queue)
但终止应用程序,我在控制台中收到以下错误:
2015-12-26 19:41:55.596 Harish Yerra [4663:132796] XPC连接中断 2015-12-26 19:41:55.596 Harish Yerra [4663:132797]终止,因为没有系统应用程序。
iPhone完全重启并返回主屏幕。
我试过评论setViewController
方法,我的应用程序加载页面视图控制器的第一页正常,然后当我滚动到下一页时,它再次崩溃,出现以下错误:
*断言失败 - [_ UIQueuingScrollView _replaceViews:updatingContents:adjustContentInsets:animated:],/ BuildRoot / Library / Cache / com.apple.xbs / Source / UIKit_Sim / UIKit-3512.30.14 / _UIQueuingScrollView.m: 377 2015-12-26 19:31:55.058 Harish Yerra [4381:123817] * 由于未捕获的异常终止应用程序' NSInternalInconsistencyException',原因:'无效参数不满意:[views算] == 3' ***第一次抛出调用堆栈: ( 0 CoreFoundation 0x000000010e411e65 exceptionPreprocess + 165 1 libobjc.A.dylib 0x00000001105b0deb objc_exception_throw + 48 2 CoreFoundation 0x000000010e411cca + [NSException raise:format:arguments:] + 106 3基金会0x000000010ea824de - [NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 198 4 UIKit 0x000000010f8d5575 - [_ UIQueuingScrollView _replaceViews:updatingContents:adjustContentInsets:animated:] + 289 5 UIKit 0x000000010f8d949d - [_ UIQueuingScrollView _didScrollWithAnimation:force:] + 1350 6 UIKit 0x000000010f8d4701 - [_ UIQueuingScrollView layoutSubviews] + 176 7 UIKit 0x000000010f1444a3 - [UIView(CALayerDelegate)layoutSublayersOfLayer:] + 703 8 QuartzCore 0x000000010ef4959a - [CALayer layoutSublayers] + 146 9 QuartzCore 0x000000010ef3de70 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 366 10 QuartzCore 0x000000010ef3dcee _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 11 QuartzCore 0x000000010ef32475 _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 277 12 QuartzCore 0x000000010ef5fc0a _ZN2CA11Transaction6commitEv + 486 13 QuartzCore 0x000000010ef6e9f4 _ZN2CA7Display11DisplayLink14dispatch_itemsEyyy + 576 14 CoreFoundation 0x000000010e371c84 __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION + 20 15 CoreFoundation 0x000000010e371831 __CFRunLoopDoTimer + 1089 16 CoreFoundation 0x000000010e333241 __CFRunLoopRun + 1937 17 CoreFoundation 0x000000010e332828 CFRunLoopRunSpecific + 488 18 GraphicsServices 0x0000000112219ad2 GSEventRunModal + 161 19 UIKit 0x000000010f08d610 UIApplicationMain + 171 20 Harish Yerra 0x000000010d813efd main + 109 21 libdyld.dylib 0x00000001115f092d start + 1 ) libc ++ abi.dylib:以NSException类型的未捕获异常终止 (LLDB)。
我将为我的viewDidLoad
提供代码,但如果你需要整个PageViewControllerDataSource的代码,请告诉我,我会提供它。非常感谢你的帮助。
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.pageViewController = harishStoryboard.instantiateViewControllerWithIdentifier("HarishPageViewController") as! UIPageViewController
self.pageViewController.dataSource = self
let initialViewController = harishStoryboard.instantiateInitialViewController() as! HarishIntroduction
let viewController = NSArray(object: initialViewController)
dispatch_async(dispatch_get_main_queue(), {
self.pageViewController.setViewControllers(viewController as? [UIViewController], direction: .Forward, animated: false, completion: nil)
})
self.pageViewController.view.frame = CGRectMake(0, 100, self.view.frame.size.width, self.view.frame.size.height-100)
self.addChildViewController(pageViewController)
self.view.addSubview(self.pageViewController.view)
self.pageViewController.didMoveToParentViewController(self)
}
答案 0 :(得分:1)
好的,非常感谢大家的帮助。但是,我想我发现了我的问题。我的第一个错误是没有将setViewControllers
方法放在dispatch_get_main_queue()
中。此外,this link帮助了我很多。它基本上告诉我在if
方法上使用viewController.isKindOfClass
语句来确定在pageViewController
beforeViewController
和afterViewController
的dataSource方法中正确导航到哪个视图方法。
我真的希望这篇文章可以帮助那些可能和我有同样问题的人。谢谢你的帮助!
答案 1 :(得分:0)
如果要创建UIPageViewController?您可以在Xcode中找到最佳细节!只需单击“基于页面的应用程序”按钮而不是“单一视图应用程序”! Apple已经通过大量代码提供了Xcode 7.2的最新更改!祝你好运!