我正在尝试将我的collectionView转换为IGListKit CollectionView。我收到错误消息:<build>
这是保存collectionView的viewController代码:
<reporting>
和我的mvn site
<?xml version="1.0" encoding="UTF-8"?>
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>mylib</artifactId>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.15</version> <!-- Update from default 6.18 to 8.15 -->
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.0.0</version>
<!-- Uncommenting will cause syntax error, Dependencies can't be declared in reporting -->
<!-- <dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>8.15</version>
</dependency>
</dependencies> -->
</plugin>
</plugins>
</reporting>
</project>
我真的不明白为什么会发生此错误。 Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: indexPath != nil'
数组也不为空,collectionViewCell正在从控制台中的单元格打印信息,因此我知道对象(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
}
}
)也不为空。这是我第一次实现IGListKit,所以我不知道是否丢失了任何东西。有人可以帮忙吗?
我尝试使用类postSectionController
将collectionView更改为普通视图,但这会产生与标题相同的错误。在正常的collectionView中,我的UICollectionViewCell类和笔尖都可以工作
答案 0 :(得分:1)
是因为您的UICollectionViewLayout
应该是UICollectionViewFlowLayout
。