UICollectionView我有一个不想水平滚动的问题。我想显示 5 个可以滚动的单元格。是什么阻止我collectionview滚动?
import UIKit
class FeaturedCell: UICollectionViewCell, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout
{
// Attributes
lazy var featuredVideos = UICollectionView(frame: .zero)
// Superclass initializer
required init?(coder aDecoder: NSCoder)
{
fatalError("init(coder:) has not been implemented")
}
// Custom initializer
required override init(frame: CGRect)
{
super.init(frame: frame)
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .Horizontal
featuredVideos = UICollectionView(frame: self.frame, collectionViewLayout: layout)
featuredVideos.dataSource = self
featuredVideos.delegate = self
// Setting the collection view's scrolling behaviour
featuredVideos.pagingEnabled = true
featuredVideos.scrollEnabled = true
featuredVideos.setContentOffset(CGPoint(x: …Run Code Online (Sandbox Code Playgroud) 我正在尝试按键(The Double)订购[Double:Article]字典.
我已经尝试了一切,现在我有以下代码:
// getting an array of sorted keys
let articlesKeys = articles.keys.sort{$0 > $1}
var sortedArticles = [Double:Article]()
// trying to fill the new dictionary in a descending keys order
for key in articlesKeys
{
sortedArticles[key] = articles[key]
}
// replacing the old dictionary (articles)
// with the new and ordered one (sortedArticles)
articles.removeAll()
articles = sortedArticles
Run Code Online (Sandbox Code Playgroud)
问题是订购了"articleKeys"
print(articleKeys)===> [220,218,110]
但是当我打印出"sortedArticles"或新的"文章"时:
print(sortedArticles)===> [110:X],[220:Y],[218:Z]
字典尚未订购:(