【发布时间】:2018-12-10 17:08:43
【问题描述】:
我正在尝试将我的 collectionView 转换为 IGListKit CollectionView。我收到错误:Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: indexPath != nil'
这里是包含 collectionView 的 viewController 代码:
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
}
}
还有我的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) {
}
}
我真的不明白为什么会发生这个错误。 lists 数组不为空,并且 collectionViewCell 正在从控制台中的单元格打印信息,因此我知道对象 (Media) 也不为空。这是我第一次实现 IGListKit,所以我不知道我是否遗漏了什么。有人可以帮忙吗?
我尝试将我的 collectionView 更改为具有 IGListCollectionView 类的普通视图,但这会产生与标题相同的错误。我的 UICollectionViewCell 类和 nib 在普通的 collectionView 中都可以工作
【问题讨论】:
-
究竟是哪一行导致了错误?
-
控制台中出现错误,因此不确定它在哪一行。但是,线程 1:信号 SIGABRT 错误出现在定义类的行的 AppDelegate 中。我觉得这可能是由于我的 nib 文件。
-
设置异常断点以获取更多信息
-
@vadian 断点首先转到应用程序委托“线程 1:信号 SIGABRT”。然后转到第 64 行: IGParameterAssert(indexPath != nil);出现错误“线程 1:断点 1.1”此行位于 IGListDisplayHandler 文件中名为“didEndDisplayingReusableView”的方法中
-
看来是断言失败
标签: ios swift uicollectionview iglistkit