Замените ваши функции и переменные, как я сделал, в настоящее время, как вы делаете с данными1, данными2, данными3 и т. Д. ... вы не можете достичь требуемой функциональности.
let dataSource = [["A", "B", "C", "D"]
,["E", "F", "G", "H"],
["I", "J", "K", "L"],
["M", "N", "O", "P"]]
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "mealCellID", for: indexPath) as! CollectionViewCell
cell.dataSource = dataSource[indexPath.item]
cell.tableView.delegate = self
cell.tableView.dataSource = self
return cell
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return dataSource.count
}
func collectionView (_collectionView: UICollectionView, макет collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {вернуть CGSize (ширина: collectionView.frame.width, высота: collectionView.frame.height)}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data1.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "dishCellID")
cell?.textLabel?.text = cell?.dataSource[indexPath.row]
return cell!
}
import UIKit
class CollectionViewCell: UICollectionViewCell, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
var dataSource = [String]()
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return dataSource.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "dishCellID")!
return cell
}
}