参数标签(forItem:,inSection :)与任何可用的重载都不匹配

rrr*_*abu 1 uicollectionview swift3

我有以下代码段,用于收集视图类别。

func indexPathForCategory(category: Category) -> NSIndexPath
    {
        let section = sections.index(of: category.section)
        var item = 0
        for (index, currentCategory) in categoriesForSection(index: section!).enumerated() {
            if currentCategory === category {
                item = index
                break
            }
        }
        return NSIndexPath(forItem: item, inSection: section!)
    }
Run Code Online (Sandbox Code Playgroud)

在return语句上,由于参数标签(forItem:,inSection :)与任何可用的重载都不匹配,因此出现错误。

Tim*_*len 5

使用NSIndexPath(item:section:)代替。