Ios 在容器中使用UICollectionViewController-Swift
我正在尝试使用嵌入在我的MainViewController上的容器中的Ios 在容器中使用UICollectionViewController-Swift,ios,uiviewcontroller,swift,uicollectionview,containers,Ios,Uiviewcontroller,Swift,Uicollectionview,Containers,我正在尝试使用嵌入在我的MainViewController上的容器中的UICollectionViewController 如下所示: 以下是我的CollectionViewController: class ExistingProjectsCollectionViewController: UICollectionViewController, UICollectionViewDelegate, UICollectionViewDataSource { override func
UICollectionViewController
如下所示:
以下是我的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在情节提要中为“单元”
我是否遗漏了一些明显的内容?问题可能是这一行:
self.collectionView.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseIdentifier)
您不需要,也不应该仅仅为了从故事板中获取单元而注册任何类。如果需要,故事板可以指定单元类。基本上,你说的是“不要从故事板中获取单元格-只需使用普通的UICollectionViewCell”,这与你想要做的恰恰相反
我按照您的描述创建了一个项目(从主视图控制器中嵌入segue),将代码复制并粘贴到中,注释掉该行,然后运行它。细胞看起来很好 @matt我的道歉,我是说UICollectionViewController-而不是UIContainerViewController