Вы должны объединить Collection-view и Tableview, чтобы иметь горизонтальную прокрутку в UICollectionView, где каждая горизонтальная строка слева направо расположена в один ряд. Каждый раздел будет занимать разные строки.
class DesignCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var lbltext: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
}
class DesignTableViewCell: UITableViewCell {
@IBOutlet weak var designCollectionView: UICollectionView!
var numberofScection = Int()
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
self.designCollectionView.register(UINib(nibName: "DesignCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "DesignCollectionViewCell")
self.designCollectionView.dataSource = self
self.designCollectionView.delegate = self
let layout = UICollectionViewFlowLayout()
layout.scrollDirection = .horizontal
self.designCollectionView.collectionViewLayout = layout
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
extension DesignTableViewCell: UICollectionViewDataSource,UICollectionViewDelegate,UICollectionViewDelegateFlowLayout{
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return 7
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "DesignCollectionViewCell", for: indexPath) as! DesignCollectionViewCell
cell.lbltext.text = "section \(self.numberofScection) indexpath \(indexPath.row)"
return cell
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: 170, height: 100.0)
}
}
class ViewController: UIViewController {
@IBOutlet weak var designTableViewCell: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.designTableViewCell.register(UINib(nibName: "DesignTableViewCell", bundle: nil), forCellReuseIdentifier: "DesignTableViewCell")
self.designTableViewCell.dataSource = self
self.designTableViewCell.delegate = self
}
}
extension ViewController: UITableViewDataSource,UITableViewDelegate{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "DesignTableViewCell") as! DesignTableViewCell
cell.designCollectionView.reloadData()
cell.numberofScection = indexPath.row
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 110
}
}