私はUITableViewを持っていて、その中に2つありますUICollectionViews
です。UICollectionViewのコンテンツサイズに応じてUITableViewCellの高さを設定する方法は?
私の必要条件は、最初にスクロールする必要があることです。UICollectionView
は水平方向です。 そして私はスクロールする必要があるのでUITableView
を垂直にスクロールする必要はありません。UICollectionView
をスクロールします。あなたがその最初の(ヘッダー「フォルダ」)を見ることができ、画像内
UICollectionView
私は水平方向と第二(ヘッダ「製品」)をスクロールする必要がUICollectionView
私はUITableView
コンプリートをスクロールする必要があるため、私は垂直方向にスクロールする必要はありません。
collectionView
はいずれもTableViewCell
であり、第2のUICollectionView
のスクロールを無効にしています。
商品を追加して削除する必要がありますが、どのようにしてTableViewSecond
セルの高さを設定する必要がありますか?ここで
私のコードです:
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if (0 == indexPath.section) {
var addFolderCell = tableView.dequeueReusableCell(withIdentifier: "AddFolderCell") as? AddFolderCell
if(nil == addFolderCell) {
let nib:Array = Bundle.main.loadNibNamed("AddFolderCell", owner: self, options: nil)!
addFolderCell = nib[0] as? AddFolderCell
}
addFolderCell?.collectionView.delegate = self
addFolderCell?.collectionView.dataSource = self
return addFolderCell!
} else {
let identifier = "CreateFolderCell"
var createFolderCell = tableView.dequeueReusableCell(withIdentifier: identifier) as? CreateFolderCell
if(createFolderCell == nil) {
let nib:Array = Bundle.main.loadNibNamed("CreateFolderCell", owner: self, options: nil)!
createFolderCell = nib[0] as? CreateFolderCell
}
return createFolderCell!
}
}
//Height for row.
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
//let index : NSIndexPath = NSIndexPath(row: 0, section: 1)
if 0 == indexPath.section {
return 135
}
return 300
}
//ヘッダの高さ。
func tableView(_ tableView: UITableView, estimatedHeightForHeaderInSection section: Int) -> CGFloat {
return 20
}
func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return sectionsArray[section] as? String
}
}
extension GroupDataView : UICollectionViewDelegate,UICollectionViewDataSource {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 4
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "AddFolderCollectionCell", for: indexPath) as! AddFolderCollectionCell
//cell.backgroundColor = UIColor.white
cell.layer.borderWidth = 0.4
cell.layer.borderColor = UIColor.lightGray.cgColor
cell.layer.cornerRadius = 2
//CreateCardView(viewCorner: cell.cardView) //cell.cardView
return cell
}
}
// MARK:コレクションビューレイアウト
extension GroupDataView : UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: 90, height: 130)
}
}
私は何ができますか?どのようにtableViewの高さを設定できますか?
tableView.rowHeightを?ストーリーボードに定義されていますか? – OhadM
はい、2番目のコレクションビューのコンテンツサイズに従って2番目のセルの高さが設定されるため、どのように設定できますか。 ありがとう – kishor0011
ViewLayoutメソッドをオーバーライドすると作業が正常に進んでいるようです。 コレクションビューのセルの高さをテーブルビューのセルの高さに渡すのは問題ですか? – OhadM