То, что вы хотите, выглядит следующим образом. Но я бы порекомендовал взглянуть на учебники для UICollectionView и UITableView и постепенно продвигаться к тому, что вы хотите реализовать. Надеюсь, вы можете понять концепцию этого. Но в теории именно так вы реализуете табличное представление внутри uicollectionviewCell.
Первый класс
class CollectionViewController: UICollectionViewCOntroller, UICollectionViewDelegateFlowLayout {
private let collectionViewCellIdentifier = "myCell"
override func viewDidLoad() {
super.viewDidLoad()
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 1
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: collectionViewCellIdentifier, for: indexPath) as! YourCustomCell
return cell
}
Тогда вы хотите, чтобы вы сделали еще один класс
class YourCustomCell: UICollectionViewCell {
lazy var tableView: UITableView = {
let tv = UITableView()
tv.delegate = self
tv.dataSource = self
tv.translatesAutoresizingMaskIntoConstraints = false
return tv
}()
}
override func didMoveToSuperview() {
super.didMoveToSuperview()
NSLayoutConstraint.activate([
tableView.topAnchor.constraint(equalTo: topAnchor, constant:0 ),
tableView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: 0),
tableView.leftAnchor.constraint(equalTo: leftAnchor, constant:0),
tableView.rightAnchor.constraint(equalTo: rightAnchor, constant: 0)
])
}
}
, а затем расширение YOurCustumCell:
extension ReceivedCell: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: cellIdentifier, for: indexPath) as! UITableViewCell // Or perhaps a custom tableview cell class swell
return cell
}