gpt4 book ai didi

ios - 在容器中使用 UICollectionViewController - Swift

转载 作者:行者123 更新时间:2023-11-29 02:43:23 27 4
gpt4 key购买 nike

我正在尝试使用嵌入到 MainViewController 容器中的 UICollectionViewController

如下所示:

enter image description here

这是我的 CollectionViewController:

class ExistingProjectsCollectionViewController: UICollectionViewController, UICollectionViewDelegate, UICollectionViewDataSource {

override func viewDidLoad() {
super.viewDidLoad()

// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false

// Register cell classes
self.collectionView.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)

}

// MARK: UICollectionViewDataSource

override func numberOfSectionsInCollectionView(collectionView: UICollectionView!) -> Int {
//#warning Incomplete method implementation -- Return the number of sections
return 1
}

override func collectionView(collectionView: UICollectionView!, numberOfItemsInSection section: Int) -> Int {
//#warning Incomplete method implementation -- Return the number of items in the section
return 1000
}

override func collectionView(collectionView: UICollectionView!, cellForItemAtIndexPath indexPath: NSIndexPath!) -> UICollectionViewCell! {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as UICollectionViewCell

// Configure the cell

return cell
}

但是,由于某种原因,当我运行该应用程序时,CollectionView 会滚动,但不包含橙色框。

  • 我试过直接在 MasterViewController 上实现它,效果很好-所以这似乎与使用容器内的 UICollectionViewController。

  • 我也试过关闭自动布局 - 但没有成功。

  • 我在 Xcode 6 Beta 6 上使用 Swift。

  • 我已确保我的可重复使用单元格 ID 在 Storyboard中是“单元格”

我错过了一些明显的东西吗?

最佳答案

问题可能出在这一行:

self.collectionView.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)

您不需要也不应该仅仅为了从 Storyboard 中获取单元格而注册任何类。如果需要, Storyboard可以指定一个单元类。基本上你是在说“不要从 Storyboard 中获取单元格 - 只需使用普通的 UICollectionViewCell 代替”,这与你想要做的完全相反。

我按照您的描述创建了一个项目(从我的主视图 Controller 中嵌入 segue),将您的代码复制并粘贴到其中,注释掉该行,然后运行它。细胞看起来很好。

关于ios - 在容器中使用 UICollectionViewController - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25452695/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com