Ios collectionView标头上的搜索栏实现
我在collectionView标题中实现了一个搜索栏 我在这里得到一个例外:Ios collectionView标头上的搜索栏实现,ios,swift,uicollectionview,uicollectionreusableview,Ios,Swift,Uicollectionview,Uicollectionreusableview,我在collectionView标题中实现了一个搜索栏 我在这里得到一个例外: func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView { let searchView: UICollectionReusableView =
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
let searchView: UICollectionReusableView = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: "SearchBarDispositivos", for: indexPath)
return searchView
}
错误消息是:源文件中的编辑器占位符。这似乎只是一个Xcode错误。完全删除SupplementalElementOfKind的
视图,清理项目,构建项目。请再次尝试添加视图以获得类的SupplmentalElement
。@oCal,我将尝试it@ocanal,完成后,错误消息消失,但启动应用程序时出现错误:2020-03-21 15:05:46.358118+0100 Jogua[15572:689310]***由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“无法将标识符为SearchBarDispositivos的UICollectionElementKindSectionHeader类型的视图出列-必须为标识符注册nib或类,或在情节提要中连接原型单元格。这是另一个错误,但您必须在viewdidload中注册该类,然后才能使用它,添加此collectionView.register(SearchBarDispositivos.self,对于种类的SupplmentalViewofKind:UICollectionView.elementKindSectionHeader,使用ReuseIdentifier:“SearchBarDispositivos”)
@ocnal,我将尝试另一种实现搜索栏的方法。非常感谢。