首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >集合视图NSException

集合视图NSException
EN

Stack Overflow用户
提问于 2015-03-30 13:18:27
回答 2查看 285关注 0票数 0

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

在控制台中:

错误:-UIViewController集合sent :numberOfItemsInSection::无法识别的选择器已发送到实例

代码语言:javascript
复制
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.
    }


}
EN

回答 2

Stack Overflow用户

发布于 2015-03-30 13:57:05

我现在还没有在斯威夫特工作。您可以查看Apple参考文档中的以下代码。有一个下划线,但我不确定这是否会有帮助。

代码语言:javascript
复制
func collectionView(_ collectionView: UICollectionView,numberOfItemsInSection section: Int) -> Int
票数 0
EN

Stack Overflow用户

发布于 2015-03-30 22:46:54

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29338865

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档