我将我的集合连接到委托和数据源,但仍然收到此错误。关于我的numberOfItmesInSection方法的实现,有什么未被识别的地方?如果需要,我可以发布更多的错误,似乎这就是它的要点。
在控制台中:
错误:-UIViewController集合sent :numberOfItemsInSection::无法识别的选择器已发送到实例
import UIKit
class ViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
var list = ["Laundry", "Do Dishes", "Vaccuum", "Run around", "Sing a song", "Get a grip", "Shoot a buffalo", "Space out", "Eat bork", "Apply to job", "Scuba doobey", "Polka Dance Marathon", "Pizza Catastrophe"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return list.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell: StandardCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as StandardCell
cell.CellLabel?.text = list[indexPath.row]
return cell
}
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
println("Cell \(indexPath.row) selected")
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}发布于 2015-03-30 13:57:05
我现在还没有在斯威夫特工作。您可以查看Apple参考文档中的以下代码。有一个下划线,但我不确定这是否会有帮助。
func collectionView(_ collectionView: UICollectionView,numberOfItemsInSection section: Int) -> Int发布于 2015-03-30 22:46:54
正如@rdelmar在评论中提到的,我在故事板中将我的视图控制器类设置为view controller而不是UIViewController,这就成功了。我不记得过去在使用tableViews做类似的事情时必须这样做,但无论如何,这就是解决方案。谢谢!
https://stackoverflow.com/questions/29338865
复制相似问题