Reputation: 416
I am trying to convert my collectionView to an IGListKit CollectionView. I am getting the error: Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: indexPath != nil'
here is the viewController code which holds the collectionView:
import UIKit
import IGListKit
import Firebase
import SAMCache
class NewHomeViewController: UIViewController {
@IBOutlet weak var collectionView: UICollectionView!
var sectionCategories: [String] = ["Friends Lists", "Friends", "People"]
var lists = [Media]()
lazy var adapter: ListAdapter = {
return ListAdapter(updater: ListAdapterUpdater(), viewController: self, workingRangeSize: 0)
}()
override func viewDidLoad() {
super.viewDidLoad()
self.collectionView.collectionViewLayout = UICollectionViewLayout()
adapter.collectionView = collectionView
adapter.dataSource = self
// check if the user logged in or not
Auth.auth().addStateDidChangeListener { (auth, user) in
if let user = user {
// signed in
WADatabaseReference.users(uid: user.uid).reference().observeSingleEvent(of: .value, with: { (snapshot) in
if let userDict = snapshot.value as? [String : Any] {
self.currentUser = User(dictionary: userDict)
print("user is signed in2")
//load the media
if self.currentUser != nil {
DispatchQueue.main.async {
self.observeMedia()
}
}
}
})
print("user is signed in")
} else {
print("user is not signed in")
self.performSegue(withIdentifier: Storyboard.showWelcome, sender: nil)
}
}
}
func observeMedia() {
Media.observeNewMedia { (media) in
print("observed")
if !self.lists.contains(media) {
self.lists.insert(media, at: 0)
print("adding")
print("\(self.lists.count)")
self.adapter.performUpdates(animated: true, completion: nil)
}
}
}
}
extension NewHomeViewController: ListAdapterDataSource {
func objects(for listAdapter: ListAdapter) -> [ListDiffable] {
let feedItems: [ListDiffable] = lists
return feedItems
}
func listAdapter(_ listAdapter: ListAdapter, sectionControllerFor object: Any) -> ListSectionController {
return postSectionController()
}
func emptyView(for listAdapter: ListAdapter) -> UIView? {
let view = UIView()
view.backgroundColor = .red
return view
}
}
and my postSectionController
import UIKit
import IGListKit
class postSectionController: ListSectionController {
var list: Media!
}
extension postSectionController {
override func numberOfItems() -> Int {
return 1
}
override func sizeForItem(at index: Int) -> CGSize {
return CGSize(width: 158, height: 203)
}
override func cellForItem(at index: Int) -> UICollectionViewCell {
print("got to cell for item")
let cell = collectionContext?.dequeueReusableCell(withNibName: "HomeListsCollectionViewCell", bundle: nil, for: self, at: index) as! HomeListsCollectionViewCell
cell.media = list
return cell
}
override func didUpdate(to object: Any) {
list = object as? Media
}
override func didSelectItem(at index: Int) {
}
}
I really do not understand why this error is occurring. The lists
array is not empty and the collectionViewCell is printing information from the cell in the console so I know that the object (Media
) is not empty either. This is my first time implementing IGListKit so I don't know if I am missing anything. Can anyone help?
I have tried changing my collectionView to a normal view with the class IGListCollectionView
but this gives the same error as the title. My UICollectionViewCell class and nib both work when in a normal collectionView
Upvotes: 2
Views: 2594
Reputation: 501
Is because your UICollectionViewLayout
should be UICollectionViewFlowLayout
.
Upvotes: 2