2017-02-09 117 views
0

我想水平滾動到一個collectionView,當我調用一個函數,並收到錯誤「無」不可用:使用[]來構造一個空的選項集 - 不知道這裏有什麼問題。 ..提前致謝!水平滾動收藏查看期號

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) 
    } 
+0

閱讀'UICollectionViewScrollPosition'的文檔。請注意缺少'none'值。 – rmaddy

回答

1

你必須提供一個位置,該項目應該滾動到。有關可能的值,請參見的documentation。同時你可以使用這個:

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