Ramotion/expanding-collection

exception

Closed this issue · 4 comments

fatal error: unexpectedly found nil while unwrapping an Optional value

Had this too in line 53 in DemoTableViewControllers scrollViewDidScroll: when interactively dismissing, presenting and dismissing again

Same problem,and @fruitcoder get the way to recreate it.

fatal error: unexpectedly found nil while unwrapping an Optional value

It seems that I fixed this by adding the button animation to the main thread:

for case let viewController as TrendDramaVC in navigationController!.viewControllers {
                if case let rightButton as AnimatingBarButton = viewController.navigationItem.rightBarButtonItem {

                    dispatch_async(dispatch_get_main_queue(), { 
                        rightButton.animationSelected(false)
                    })
                }
            }
            popTransitionAnimation()

Consider fixing it with a more "Swifty approach"

override func scrollViewDidScroll(scrollView: UIScrollView) {
  if scrollView.contentOffset.y < -25 , let navigationController = navigationController {
    // buttonAnimation
    for case let viewController as DemoViewController in navigationController.viewControllers {
      if case let rightButton as AnimatingBarButton = viewController.navigationItem.rightBarButtonItem {
        rightButton.animationSelected(false)
      }
    }
    popTransitionAnimation()
  }
  scrollOffsetY = scrollView.contentOffset.y
}