【发布时间】:2017-02-12 12:16:54
【问题描述】:
我是编码初学者,我想学习设计 iOS 移动应用程序。我通过重新创建通过观看 Youtube 构建的应用程序来学习。我目前正在重新创建 Facebook 新闻提要。下面是我学到的自定义代码。我被困在我们构建单元的部分和它们的大小上。具体来说,我收到一个错误:collectionView?.registerClass(FeedCell.self, forCellWithReuseIdentifier: cellId)。这似乎在以前的 Swift 版本中是可行的,但不适用于 3.0。谢谢大家的帮助!
代码如下:
import UIKit
let cellId = "cellId"
class FeedController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
override func viewDidLoad() {
super.viewDidLoad()
navigationItem.title = "Facebook Feed"
collectionView?.backgroundColor = UIColor(white: 0.95, alpha: 1)
collectionView?.registerClass(FeedCell.self, forCellWithReuseIdentifier: cellId)
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 3
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
return collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath)
}
func collectionView(_collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: view.frame.width, height: 50)
}
}
class FeedCell: UICollectionViewCell {
override init(frame: CGRect){
super.init(frame: frame)
setupViews()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func setupViews() {
backgroundColor = UIColor.white
【问题讨论】:
标签: ios swift3 uicollectionview