コレクションビューの一部としてコレクションビューを使用することに興味がありますが、何らかの理由でこれがどのように行われるのか把握できません。どのように私は細胞コレクションビューのための必要なメソッドを実装するだろうか?UICollectionViewCellのUICollectionView
答えて
の中にUICollectionView
を入れる方法を説明しているan article that Ash Furrow wroteがあります。 UICollectionViewCell
の内部で使用する場合、基本的に同じ考えです。
これはこの回答には遅すぎるものの、他の人にとっては役立つかもしれません。これはUICollectionViewCell
の中のUICollectionView
の例です。
まず、mainCollectionView
という文字列を使用します。そして、このコレクションの各セルにそれを行うためのUICollectionView
新しい、適切な場所を作成し、初期化しUICollectionView
func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath)
のこの以下のデリゲートで、私はここにMainCollectionViewCell
を初期化してからMainCollectionViewCell
例えば、作成するロジックを処理していますここでは新しいUICollectionView
guard let collectionViewCell = cell as? MainCollectionViewCell else { return }
collectionViewCell.delegate = self
let dataProvider = ChildCollectionViewDataSource()
dataProvider.data = data[indexPath.row] as NSArray
let delegate = ChildCollectionViewDelegate()
collectionViewCell.initializeCollectionViewWithDataSource(dataProvider, delegate: delegate, forRow: indexPath.row)
collectionViewCell.collectionViewOffset = storedOffsets[indexPath.row] ?? 0
は新しいUICollectionView
MainCollectionViewCell
の初期化子です
func initializeCollectionViewWithDataSource<D: protocol<UICollectionViewDataSource>,E: protocol<UICollectionViewDelegate>>(dataSource: D, delegate :E, forRow row: Int) {
self.collectionViewDataSource = dataSource
self.collectionViewDelegate = delegate
let flowLayout = UICollectionViewFlowLayout()
flowLayout.scrollDirection = .Horizontal
let collectionView = UICollectionView(frame: self.bounds, collectionViewLayout: flowLayout)
collectionView.registerClass(UICollectionViewCell.self, forCellWithReuseIdentifier: reuseChildCollectionViewCellIdentifier)
collectionView.backgroundColor = UIColor.whiteColor()
collectionView.dataSource = self.collectionViewDataSource
collectionView.delegate = self.collectionViewDelegate
collectionView.tag = row
self.addSubview(collectionView)
self.collectionView = collectionView
collectionView.reloadData()
}
希望がある!
私はこれを例にしてgithubに載せました。これはUICollectionViewCell
の中にUICollectionView
の使用を示しています。
https://github.com/irfanlone/Collection-View-in-a-collection-view-cell
すべてがプログラム的に行われています。ストーリーボードはありません。
UICollectionViewCellの中にUICollectionViewを追加しました。また、私は私のUICollectionViewController
は、全体の説明はしてみましょう「で見つけることができ、開発されたimport UIKit
class FeaturedAppsController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
let cellId = "cell"
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
collectionView?.backgroundColor = .white
collectionView?.register(CategoryCell.self, forCellWithReuseIdentifier: cellId)
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 3
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath)
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(view.frame.width, 150)
}
}
import UIKit
class CategoryCell: UICollectionViewCell, UICollectionViewDataSource, UICollectionViewDelegate, UICollectionViewDelegateFlowLayout {
private let cellId = "cell"
override init(frame: CGRect) {
super.init(frame: frame)
setupViews()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
let appsCollectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout()
let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
return collectionView
}()
func setupViews() {
backgroundColor = .blue
addSubview(appsCollectionView)
appsCollectionView.delegate = self
appsCollectionView.dataSource = self
appsCollectionView.register(AppCell.self, forCellWithReuseIdentifier: cellId)
addConstrainstWithFormat("H:|-8-[v0]-8-|", views: appsCollectionView)
addConstrainstWithFormat("V:|[v0]|", views: appsCollectionView)
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 5
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: cellId, for: indexPath)
return cell
}
}
class AppCell: 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 = .red
}
}
この結果を持って作成されたUICollectionViewの内側に再びUICollectionViewCellを追加する方法を示していますそのアプリをビルドする」:https://www.youtube.com/watch?v=Ko9oNhlTwH0&list=PL0dzCUj1L5JEXct3-OV6itP7Kz3tRDmma
- 1. UICollectionViewを含むUICollectionViewCell
- 2. UICollectionViewCellとUICollectionViewの等高さ
- 3. UICollectionView - cellForItemAtで返されるUICollectionViewCellのリスト
- 4. UICollectionViewCellのUICollectionView遅い/遅いスクロール
- 5. UICollectionViewとUICollectionViewCellが機能しない
- 6. UICollectionView - forループでUICollectionViewCellを返します
- 7. UICollectionViewのサイズ変更後にUICollectionViewCellのサイズを変更する
- 8. 水平スクロールUICollectionView内のUICollectionViewCellでの垂直スクロール
- 9. UICollectionViewのUICollectionReusableViewは、UICollectionViewCellのタップを防止/ブロックします。
- 10. UICollectionView内のすべてのUICollectionViewCellをアニメーション化する
- 11. UICollectionViewにIBのUICollectionViewCellがありません
- 12. 既存のUICollectionViewにさらにUICollectionViewCellを追加します。
- 13. UICollectionViewからuicollectionViewCellをポップする方法は?
- 14. UICollectionViewCellからUICollectionViewを参照する方法は?
- 15. UICollectionViewのUICollectionViewCellを垂直にどのように配置しますか?
- 16. UICollectionViewがスクロールしているときにUICollectionViewCellを無効にする方法3
- 17. UICollectionViewCellのカスタムヒットテスト
- 18. UICollectionViewCellとUIViewの
- 19. UITableViewCell/UICollectionViewCellのコンテキスト
- 20. UICollectionViewCellのUILabel
- 21. UICollectionViewCellサブクラスのinit ... ...
- 22. UICollectionViewCell内のテキストフィールド
- 23. UICollectionViewCellのUIAlertController
- 24. UICollectionViewCell Shake
- 25. UICollectionViewCell overlapping
- 26. Expandable UICollectionViewCell
- 27. セグエUICollectionViewCell
- 28. サブクラスUICollectionViewCell
- 29. アウトレットUICollectionViewCell
- 30. UICollectionViewCellサイズゼロストーリーボード