集合查看NSException

时间:2015-03-30 05:18:27

标签: ios xcode swift

我将我的集合连接到委托和数据源,但我仍然遇到此错误。我对numberOfItmesInSection方法的实现有什么未被认识的?如果需要,我可以发布更多的错误,似乎这是它的要点。

来自控制台:

错误: - [UIViewController collectionView: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.
    }


}

2 个答案:

答案 0 :(得分:0)

我现在不是在迅速工作。您可以从Apple参考文档中查看以下代码。有一个下划线,但我不确定这会有所帮助。

func collectionView(_ collectionView: UICollectionView,numberOfItemsInSection section: Int) -> Int

答案 1 :(得分:0)

正如@rdelmar在评论中提到的,我将故事板中的视图控制器类设置为View Controller而不是UIViewController,这就是诀窍。在使用tableViews做类似的事情时,我不记得过去必须这样做,但无论如何这都是解决方案。谢谢!