水平滚动集合查看问题

时间:2017-02-09 23:15:45

标签: ios swift3 uicollectionview uicollectionviewlayout

我正在尝试在调用函数时水平滚动到collectionView并且收到错误' none'不可用:使用[]构建一个空选项集 - 不确定这里有什么问题...提前致谢!

  func handleSearch() {
        scrollToMenuIndex(menuIndex: 2)
    }

    func scrollToMenuIndex(menuIndex: Int) {
        let indexPath = NSIndexPath(item: menuIndex, section: 0)
        collectionView?.scrollToItem(at: indexPath as IndexPath, at: .none, animated: true)
    }

1 个答案:

答案 0 :(得分:1)

您必须提供应滚动项目的位置。有关可能的值,请参阅documentation UICollectionViewScrollPosition。在此期间你可以使用它:

collectionView?.scrollToItem(at: indexPath as IndexPath, at: .left, animated: true)