質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

Q&A

0回答

1068閲覧

iOS14になってからtableView内のCollectionViewが横スクロールできなくなった

atk_721

総合スコア62

Swift

Swiftは、アップルのiOSおよびOS Xのためのプログラミング言語で、Objective-CやObjective-C++と共存することが意図されています

0グッド

1クリップ

投稿2020/09/18 04:10

前提・実現したいこと

tableView内のCollectionViewが横スクロールできなくなり困っています。
iOS14にアップデート後にスクロールできなくなりました。
tableViewのCellにCollectionViewをtableViewCellいっぱいに表示している表示しています。
CollectionViewCellをタップしてもdidselectItemAtは呼ばれません。

該当のソースコード

MainController

import UIKit import FirebaseAuth class MainController: UIViewController, UISearchControllerDelegate{ //MARK: - Properties 長いので割愛 fileprivate func configureTableView() { tableView.delegate = self tableView.dataSource = self tableView.register(UITableViewCell.self, forCellReuseIdentifier: tableCell) tableView.rowHeight = 220 tableView.tableFooterView = UIView() tableView.register(MainTableCell.self, forCellReuseIdentifier: tableCell) tableView.register(SectionHeaderView.self, forHeaderFooterViewReuseIdentifier: sectionReuseIdentifier) tableView.contentInsetAdjustmentBehavior = .never tableView.frame = view.frame view.addSubview(tableView) tableView.anchor(top: view.topAnchor, left: view.leftAnchor, right: view.rightAnchor, bottom: view.bottomAnchor) } //MARK: - UITableView Datasource delegate extension MainController: UITableViewDelegate, UITableViewDataSource { func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { guard let header = tableView.dequeueReusableHeaderFooterView(withIdentifier: sectionReuseIdentifier) as? SectionHeaderView else { return nil } header.frame = CGRect(x: 0, y: 0, width: view.frame.width, height: 60) header.prefecturesName = ProduceingArea.init(rawValue: section)?.description return header } func numberOfSections(in tableView: UITableView) -> Int { return isSearchMode ? searchResults.count : allProducingArea.count } func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { guard let cell = cell as? MainTableCell else { return } cell.setCollectionViewDataSourceDelegate(dataSourceDelegate: self, forRow: indexPath.section) } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 1 } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell = tableView.dequeueReusableCell(withIdentifier: tableCell, for: indexPath) as! MainTableCell return cell } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { tableView.deselectRow(at: indexPath, animated: true) } } //MARK: CollectionView Delegate DataSource extension MainController: UICollectionViewDelegate, UICollectionViewDataSource { func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return 10 } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCell(withReuseIdentifier: collectionCell, for: indexPath) as! MainCollectionCell let address = Address(prefecture: ProduceingArea(rawValue: 0), city: "osaka", townOrVillage: "umeda", address: "", detailInfo: "") let item = Item(price: 4500, inStock: 5, itemName: "test", sellerName: "test", sellerImage: "", address: address, images: [], description: "Hello") cell.item = item return cell } func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { print("collectionCell Taped") } } //MARK: - CollectionView Flowlayout extension MainController: UICollectionViewDelegateFlowLayout { func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { return CGSize(width: 180, height: 200) } func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets { return collectionSectionInSets } func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat { return collectionSectionInSets.left } func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat { return collectionSectionInSets.left } } //MARK: - UISearchResultsUpdating extension MainController: UISearchResultsUpdating { func updateSearchResults(for searchController: UISearchController) { guard let searchText = searchController.searchBar.text?.lowercased() else { return } if allProducingArea.description == searchText { self.allProducingArea = [] } self.tableView.reloadData() } }

MainTableViewCell

import UIKit private let customerCell = "customerCell" class MainTableCell: UITableViewCell { //MARK: - Properties lazy var collectionView: UICollectionView = { let layout = UICollectionViewFlowLayout() layout.scrollDirection = .horizontal layout.estimatedItemSize = .init(width: 180, height: 200) let collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout) return collectionView }() //MARK: - View LifeCycle override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) let view = UIView() self.addSubview(view) view.anchor(top: topAnchor, left: leftAnchor, right: rightAnchor, bottom: bottomAnchor, paddingTop: 8, padddingLeft: 8, paddingBottom: -8) view.addSubview(collectionView) collectionView.anchor(top: view.topAnchor, left: view.leftAnchor, right: view.rightAnchor, bottom: view.bottomAnchor) collectionView.register(MainCollectionCell.self, forCellWithReuseIdentifier: collectionCell) collectionView.backgroundColor = .clear } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } override func setSelected(_ selected: Bool, animated: Bool) { super.setSelected(selected, animated: animated) } //MARK: - Helpers func setCollectionViewDataSourceDelegate<D: UICollectionViewDataSource & UICollectionViewDelegate>(dataSourceDelegate: D, forRow row: Int) { collectionView.delegate = dataSourceDelegate collectionView.dataSource = dataSourceDelegate collectionView.showsHorizontalScrollIndicator = false collectionView.reloadData() } }

##MainCollectionViewCell

import UIKit import SDWebImage class MainCollectionCell: UICollectionViewCell { //MARK: - Properties **文字数制限のため割愛 //MARK: - View Life Cycle override init(frame: CGRect) { super.init(frame: frame) self.backgroundColor = .white } override func layoutSubviews() { super.layoutSubviews() self.layer.cornerRadius = 12 setUpCollectionCell() } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } //MARK: - Helpers func setUpCollectionCell() { addSubview(itemImageView) itemImageView.anchor(top: topAnchor, left: leftAnchor, right: rightAnchor, height: 120, width: 180) addSubview(itemNameLabel) itemNameLabel.anchor(top: itemImageView.bottomAnchor ,left: leftAnchor, right: rightAnchor, padddingLeft: 10, paddingRight: -10, height: 30) addSubview(sellerImage) sellerImage.anchor(top: itemNameLabel.bottomAnchor, left: leftAnchor) sellerImage.setDimension(height: 20, widht: 20) addSubview(sellerNameLabel) sellerNameLabel.anchor(top: itemNameLabel.bottomAnchor, left: sellerImage.rightAnchor,padddingLeft: 4, height: 20, width: 70) addSubview(priceLabel) priceLabel.anchor(top: itemNameLabel.bottomAnchor, left: sellerNameLabel.rightAnchor, right: rightAnchor, padddingLeft: 4, paddingRight: -2) priceLabel.setDimension(height: 20, widht: 80) addSubview(itemDescriptionLabel) itemDescriptionLabel.anchor(top: sellerNameLabel.bottomAnchor, left: leftAnchor, right: rightAnchor, bottom: bottomAnchor, padddingLeft: 3, paddingRight: -3) } }

補足情報(FW/ツールのバージョンなど)

ios14 xcode12 swift5.3

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

mskRR

2020/09/18 16:24 編集

delegateが設定されていないときの動作なのでしょうが、delegateは設定されていますか? willDisplayでgurad節のあとで設定されていますが、gurad節で処理がキャンセルされても気づかなそうです。 良ければ確認してみてください。問題の切り分けにはなると思います。
atk_721

2020/09/19 02:35

回答ありがとうございます!確認してみましたがguard節で処理は止まっていませんでした!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問