我创建了一个 UICollectionView Xib 文件和类文件作为 swift 包。类文件中的方法是可以访问的,但我在项目中加载 nib 文件时遇到错误。
包链接: https: //github.com/PranayChander/package1
项目链接: https: //github.com/PranayChander/packman
导入 UIKit 导入包1
class ViewController: UIViewController {
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
collectionView.register(UINib(nibName: "PackageCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "cell")
}
}
extension ViewController: UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 10
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! PackageCollectionViewCell
cell.configureCell(title: "Pram", subtitle: "dasd")
return …Run Code Online (Sandbox Code Playgroud) package-managers ios uicollectionview swift-package-manager ios14