小编Sn1*_*kkN的帖子

Swift UICollectionView 水平滚动不起作用

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)

iphone scroll ios uicollectionview swift

5
推荐指数
1
解决办法
1万
查看次数

iOS Swift如何通过键订购Dictionnary

我正在尝试按键(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]

字典尚未订购:(

sorting dictionary ios swift

1
推荐指数
1
解决办法
765
查看次数

标签 统计

ios ×2

swift ×2

dictionary ×1

iphone ×1

scroll ×1

sorting ×1

uicollectionview ×1