fatal error: unexpectedly found nil while unwrapping an Optional value at this line outDragDropCollectionView.draggingDelegate = self
Closed this issue · 16 comments
Dara and Drop in my project was working fine until I used this library. I have a viewcontroller that requires Drag and Drop and need sidemen animation.I am using SSASideMenu for SideMenu animation and to apply Sidemenu we need a root view controller.
To setup SSASideMenu we need this code in AppDelegate file
// MARK : Setup SSASideMenu
let sideMenu = SSASideMenu(contentViewController: UINavigationController(rootViewController: FirstViewController()), leftMenuViewController: LeftMenuViewController(), rightMenuViewController: RightMenuViewController())
sideMenu.backgroundImage = UIImage(named: "Background.jpg")
sideMenu.configure(SSASideMenu.MenuViewEffect(fade: true, scale: true, scaleBackground: false))
sideMenu.configure(SSASideMenu.ContentViewEffect(alpha: 1.0, scale: 0.7))
sideMenu.configure(SSASideMenu.ContentViewShadow(enabled: true, color: UIColor.blackColor(), opacity: 0.6, radius: 6.0))
sideMenu.delegate = self
window?.rootViewController = sideMenu
window?.makeKeyAndVisible()
When I set the rootViewController as HomeViewController in the AppDelegate the error Occurs what to do next make everything work as normal ???
Where is it crashing exactly? Try add an exception breakpoint. I'm not even entirely sure it's related to dragDropCollectionView
At this line outDragDropCollectionView.draggingDelegate = self
Can you show me the code that you have inside that function? Did you initialize outDragDropCollectionView?
I only have this code inside viewdidload
outDragDropCollectionView.draggingDelegate = self
outDragDropCollectionView.enableDragging(true)
Are you using storyboards?
Yes.
I get the feeling you havent initialized your collection view properly. To test, try add print(outDragDropCollectionView)
before you set the draggingDelegate, does it crash there?
Let me try
Getting this error fatal error: unexpectedly found nil while unwrapping an Optional value
Yes then that means you havent initialized your collectionView properly. Are you sure you have set up storyboards correctly?
I think So... It was working until I have added Homeviewcontroller as the root controller in app delegate file.
I just followed the library and is this enough @IBOutlet weak var outDragDropCollectionView: DragDropCollectionView!
??? or need any other initialisation ?
In your storyboard, did you remember to make your UICollectionView a subclass of DragDropCollectionView?
Yes...
@IBOutlet weak var outDragDropCollectionView: DragDropCollectionView!
Mmm difficult for me to diagnose without looking at your project. Anyways this issue is unrelated to DragDropCollectionView, hence closing
Okay... So let me try the same with SSASideMenu ... :)