I have a UICollectioView that works fine. There are 2 ways to get to this page.
- though the app.
- tap on push notification.
Everything works good except one case.
if the user is in the chat and then he exits the app (home button) then he gets a push notification he presses it and the the app crashes.
crash:
2015-09-25 10:28:15.140 Quest[298:16922] * Assertion failure in -[UICollectionView _createPreparedSupplementaryViewForElementOfKind:atIndexPath:withLayoutAttributes:applyAttributes:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit/UIKit-3505.16/UICollectionView.m:1519 2015-09-25 10:28:15.146 Quest[298:16922] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UICollectionView dataSource is not set' *** First throw call stack: (0x1828b4f5c 0x1973b7f80 0x1828b4e2c 0x1837a3f3c 0x187f97a38 0x187e6ebd4 0x187e6fb54 0x187e69b88 0x187e0700c 0x18760df14 0x187608b20 0x1876089e0 0x18760807c 0x187607dd0 0x1880c0bd4 0x18286c48c 0x18286bdc4 0x182869d4c 0x182798dc0 0x18d8ec088 0x187e72f60 0x100215590 0x197be28b8) libc++abi.dylib: terminating with uncaught exception of type NSException
code in push handler:
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
let home = storyboard.instantiateViewControllerWithIdentifier("home") as! HomeViewController
let chat = storyboard.instantiateViewControllerWithIdentifier("chat") as! ChatViewController
var controllers : [UIViewController] = [login, chat]
NotificationManager.handleNotification(userInfo, controllers: &controllers, storyboard: storyboard)
navC.viewControllers = controllers
self.window?.makeKeyAndVisible()
}
collectioview setting code
@IBOutlet weak var chatCollectionView: UICollectionView! {
didSet {
chatCollectionView.registerNib(UINib(nibName: "ChatTimeStampCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "ChatTimeStampCell")
chatCollectionView.registerNib(UINib(nibName: "ChatReceiverCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "ChatReceiverCell")
chatCollectionView.registerNib(UINib(nibName: "ChatSenderCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "ChatSenderCell")
chatCollectionView.registerNib(UINib(nibName: "ChatHeaderCollectionReusableView", bundle: nil), forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "ChatHeaderCell")
chatCollectionView.dataSource = self
chatCollectionView.delegate = self
}
}
If you are using custom layout in your collection view, check if its datasource is nil in:
The result should look something like this:
This change resolves the following issue:
You can also check the following topics, however they didn't resolve anything in my case: UICollectionView and Supplementary View (header)
Removing empty space, if the section header is hidden in the UICollectionView
Hope it will help you, and you won't waste as much time as I did. @eeeee thank you for pointing me in the right direction.