【发布时间】:2016-09-18 13:39:22
【问题描述】:
我正在尝试在自定义键盘扩展中实现 UICollectionView,但它不起作用。
这就是我在viewDidLoad 方法中所做的。
let layout: UICollectionViewFlowLayout = UICollectionViewFlowLayout()
layout.sectionInset = UIEdgeInsets(top: 20, left: 10, bottom: 10, right: 10)
layout.itemSize = CGSize(width: 90, height: 120)
collectionView = UICollectionView(frame: self.view.frame, collectionViewLayout: layout)
collectionView.dataSource = self
collectionView.delegate = self
collectionView.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: "Cell")
collectionView.backgroundColor = UIColor.whiteColor()
self.view.addSubview(collectionView)
我在我的类中添加了UICollectionViewDelegateFlowLayout 和UICollectionViewDataSource 协议,然后实现了dataSource 方法,如下所示
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 14
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath)
cell.backgroundColor = UIColor.orangeColor()
return cell
}
相同的代码在 app bundle 中按预期工作。我不明白为什么它在键盘扩展中有不同的行为。
我在这里有什么遗漏吗,我需要做什么才能让它在键盘扩展中工作?
【问题讨论】:
标签: ios objective-c swift uicollectionview custom-keyboard