-
Notifications
You must be signed in to change notification settings - Fork 0
/
GuideTableViewCell.swift
88 lines (70 loc) · 3.03 KB
/
GuideTableViewCell.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//
// GuideTableViewCell.swift
// tourismtemplate
//
// Created by G0yter on 11.05.2021.
// Copyright © 2021 xamoom GmbH. All rights reserved.
//
import UIKit
enum GuideCellDisplayType {
case quizScore
case quizPageScreen
}
class GuideTableViewCell: UITableViewCell {
public static let identifier = "GuideTableViewCell"
@IBOutlet weak var titleLabel: UILabel!
@IBOutlet weak var collectionView: UICollectionView!
var delegate : GuideInteractionProtocol?
var title: String? {
didSet {
self.titleLabel.text = title
}
}
var quizScoreItem = GuideItem.init(title: "Punktestand", image: Globals.isBackgroundImage == "true" ? UIImage(named: "background_score") : nil, displayType: .quizScore)
var quizPageScreenItem = GuideItem.init(title: "Rätselübersicht", image: Globals.isBackgroundImage == "true" ? UIImage(named: "background_overview") : nil, displayType: .quizPageScreen)
var items: [GuideItem] = []
override func awakeFromNib() {
super.awakeFromNib()
initCollectionView()
}
func initCollectionView() {
collectionView.register(
UINib(nibName: "GuideCollectionViewCell", bundle: Bundle.main),
forCellWithReuseIdentifier: GuideCollectionViewCell.identifier)
items = [quizScoreItem, quizPageScreenItem]
print(Globals.Features.quiz)
collectionView.dataSource = self
collectionView.delegate = self
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}
}
extension GuideTableViewCell: UICollectionViewDelegate {
func collectionView(_ collectionView: UICollectionView,
didSelectItemAt indexPath: IndexPath) {
self.delegate?.didClick(itemPosition: indexPath.row, cellIdentifier: items[indexPath.row].displayType)
}
}
extension GuideTableViewCell: UICollectionViewDataSource {
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return items.count;
}
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
var cell: GuideCollectionViewCell!
cell = collectionView.dequeueReusableCell(withReuseIdentifier: GuideCollectionViewCell.identifier, for: indexPath) as! GuideCollectionViewCell
cell.configureCell(item: items[indexPath.row])
return cell;
}
}
extension GuideTableViewCell: UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return Globals.Size.contentCollectionViewCellSize
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -> UIEdgeInsets {
return Globals.Size.contentCollectionViewInsets
}
}