2

When I run my app, I notice that the setViewController method causes a memory link and crashes my app.I have worked on this issue for hours, and have tried looking on the web, and found one post, which mentioned putting my setViewController method in the dispatch_async(dispatch_get_main_queue) but that terminates the app, and I get the following error in the console:

2015-12-26 19:41:55.596 Harish Yerra[4663:132796] XPC connection interrupted 2015-12-26 19:41:55.596 Harish Yerra[4663:132797] Terminating since there is no system app.

The iPhone than fully restarts and goes back to the home screen.

I have tried commenting out the setViewController method, and my app loads the first page of the Page View Controller fine, and then when I scroll to the next page it crashes again with the following error:

* Assertion failure in -[_UIQueuingScrollView _replaceViews:updatingContents:adjustContentInsets:animated:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.30.14/_UIQueuingScrollView.m:377 2015-12-26 19:31:55.058 Harish Yerra[4381:123817] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: [views count] == 3' *** First throw call stack: ( 0 CoreFoundation 0x000000010e411e65 exceptionPreprocess + 165 1 libobjc.A.dylib 0x00000001105b0deb objc_exception_throw + 48 2 CoreFoundation 0x000000010e411cca +[NSException raise:format:arguments:] + 106 3 Foundation 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: terminating with uncaught exception of type NSException (lldb).

I will provide the code for my viewDidLoad, but if you need the code for the entire PageViewControllerDataSource, just let me know and I will provide it. Thanks so much for your help.

    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)
}
Community
  • 1
  • 1
Harish
  • 1,374
  • 17
  • 39
  • You're running that on a real device? :O – HAS Dec 27 '15 at 08:56
  • The same thing happens when running in real device or on the simulator. – Harish Dec 27 '15 at 14:52
  • Please file a bug at bugreport.apple.com. Under no circumstances should your app crash the system! – HAS Dec 27 '15 at 14:55
  • 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: [views count] == 3' says that you need 3 views. So you update all your UI on the main thread? – HAS Dec 27 '15 at 15:21
  • @HAS I think I found the issue to my app, but even I was confused because the whole system crashed and my iPhone restarted even when running on a real device. I started running my app in the simulator because I was scared I would break the phone. I will file a bug report though just so Apple knows that there is some code which could potentially crash the system. – Harish Dec 27 '15 at 15:22

2 Answers2

1

Ok, thanks so much for your help everybody. However, I think I found what my problem was. My first error was not putting the setViewControllers method in dispatch_get_main_queue(). Also, this link helped me out a lot. It basically told me to use if statements on the viewController.isKindOfClass method to determine which view to correctly navigate to in the dataSource methods of the pageViewController beforeViewController, and afterViewController methods.

I really hope this post helps anybody else who might have the same issue as me. Thanks for your help, though!

Community
  • 1
  • 1
Harish
  • 1,374
  • 17
  • 39
0

If you want create a UIPageViewController? You can find best details in your Xcode! Just click the button " Page Based Application " instead of the " Single View Application "! Apple already been provided latest changes in Xcode 7.2 with huge line of codes! Good luck!

Amateur User
  • 91
  • 1
  • 10
  • Ya, but only part of my app is a PageViewController not all of it. Also, I have created a large portion of my app so it would be a pain to start over. However, is it possible to import an Xcode Project into another Xcode Project? – Harish Dec 27 '15 at 03:28
  • @Harish you can select page based application in another project & copy & paste that view controller into your current project – Ajinkya Patil Dec 27 '15 at 03:48
  • 1
    @AjinkyaPatil Ok, I will try that, but the only issue is I have the majority of the whole PageViewController setup done. As a result, I really want to try to fix the issue, and if there is no solution to fixing the issue I will use the template that Apple has provided. – Harish Dec 27 '15 at 03:52