SSAC iOSアプリケーション開発者デビュープロセス-14
🎛 Collection View
UICollectionView
は、カスタマイズ可能なレイアウトを使用してユーザに複数のデータを表示するオブジェクトである.使用方法と大きなフレームワークは,前に学習した
Table View
とあまり変わらない.このことは、View Controller
にCollection View
を追加することによって達成される.1)Collection View Cellの作成
作成
Collection View
は、XIBファイル形式で前回作成されたTable View Cell
と同じです.前回の説明では、
Collection View Cell
という形でcellを1つ作成すると、このcellを繰り返し使用するのは簡単ですが、XIB
ファイルとXib
の違いは説明されていないので、簡単に説明します.Nib
: Xml Interface Builder xib
: Next Interface Builder nib
ファイルがコンパイルされると、xib
ファイルに変換されます.では、なぜ
nib
ファイルを使用しなければならないのでしょうか.100」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」「」
人はコードが読めないのでバージョン管理も難しいので、人が読めない
xib
ファイルと一緒に使えます.では、
nib
ファイルでcellを作成して使用すると、xib
形式で登録する必要がある理由が理解できます.xib
2)Collection Viewの追加nib
を構成するユニットの設計を完了しました.❗️ identifier 설정 잊지말기!!
にCollection View
を追加する必要があります.ViewController
ではなくコレクションビューを使用しています.Collection View
プロトコルが必要です.このパターンを
Collection ViewController
と呼ぶ.extension StudyCollectionViewController:
UICollectionViewDelegate, UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
}
まず、以下に示すように、現在のViewControllerのクラスファイルに拡張子を追加します.CollectionViewDelegate, CollectionViewDataSource
class StudyCollectionViewController: UIViewController {
@IBOutlet weak var collectionView: UICollectionView!
override func viewDidLoad() {
super.viewDidLoad()
collectionView.delegate = self
collectionView.dataSource = self
let nibNmae = UINib(nibName: "StudyCollectionViewCell ", bundle: nil)
collectionView.register(nibNmae, forCellWithReuseIdentifier: StudyCollectionViewCell.identifier)
}
}
次に、委任者を特定するプロセスが必要です.Delegate Pattern
Delegate Pattern 에 대해서 더 알게되면 자세하게 따로 정리하겠습니다.
3)Collection View Layoutの設定(ViewController 라는 알바생이 할 일들을 정리)
を使用すると、コレクションビューのセルを所望のシェイプでソートできます.セルを設定する場合、
collectionView 라는 사장이 StudyCollectionViewController(self) 가 알바생임을 선언
はセルの外観(高さ)を設定し、UICollectionView FlowLayout
はFlowLayoutクラスで設定します.TableView
ブログ1 ブログ2
FlowLayoutの様々な製品を知ることができます.
🏷 P.S.
昨日
Collection View
の内部のボタンである動作を実現しようとしたが失敗し、今日の授業で勉強した부스토코스 이미지를 사용했습니다!
とcustom cell
を利用して成功した.override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(withIdentifier: "MainTableViewCell", for: indexPath) as? MainTableViewCell else {
return UITableViewCell()
}
let row = tvShowInformation.tvShow[indexPath.row]
cell.totalView.clipsToBounds = true
cell.totalView.layer.cornerRadius = 10
cell.genreLabel.text = row.genre
cell.releaseDayLabel.text = row.releaseDate
cell.titileLabel.text = row.title
cell.rateLabel2.text = " \(row.rate) "
cell.overViewLabel.numberOfLines = 1
cell.overViewLabel.text = row.starring
let url = URL(string: row.backdropImage)
let data = try? Data(contentsOf: url!)
cell.posterImageView.image = UIImage(data: data!)
cell.detailButton.tag = indexPath.row
cell.detailButton.addTarget(self, action: #selector(detailButtonClicked(selectButton:)), for: .touchUpInside)
return cell
}
@objc
func detailButtonClicked(selectButton: UIButton) {
let sb = UIStoryboard(name: "Main", bundle: nil)
let vc = sb.instantiateViewController(withIdentifier: "DetailViewController") as! DetailViewController
print(tvShowInformation.tvShow[selectButton.tag].title)
//이렇게 바로 넣으면 오류
//vc.titleLabel?.text = tvShowInformation.tvShow[selectButton.tag].title
vc.movieLable = tvShowInformation.tvShow[selectButton.tag].title
present(vc, animated: true, completion: nil)
}
忘れる前にハーモニーを整理してまず、私たちが設計したカスタムユニットに存在するボタンを押すと、
addTarget
画面に切り替え、変換後の画面のラベルをユニットの情報に渡すことを目的としています.各セルには異なる情報があり、画面遷移のラベルにこれらの情報を表示する必要があるため、
tag
の(show)
のcell
の情報が必要です.ただし、cellクラスファイル、ViewControlクラスファイルではindexPath情報は使用できません.
indexPath
を使用!tag
このコードでtableviewで各セルを作成する場合は、セルのcell.detailButton.tag = indexPath.row
をindexPath.row
に保存してください.次に、各セルのボタンを
tag
で関数に設定して、実行する操作を決定します.この関数はDetailButtonClickedという名前の関数に設定されています.これは昨日習ったパスデータと同じです.
addTarget
그냥 바로 전환될 화면의 Label 에 값을 넣도록 설정하면 오류
コレクションビューやtableviewはコンセプト学習だけでなく、私が望む画面を作成するプロセスが絶対に必要だと思います.
これからもっとやりながら整理を続けます!
Reference
この問題について(SSAC iOSアプリケーション開発者デビュープロセス-14), 我々は、より多くの情報をここで見つけました https://velog.io/@cold929/SSAC-iOS-앱-개발자-데뷔과정-14テキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol