Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extension SearchController: UITableViewDataSource {
- func numberOfSections(in tableView: UITableView) -> Int {
- return 1
- }
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- switch currentSearchType {
- case .menuItems:
- return menuItemResults.count
- case .restaurants:
- return restaurantResults.count
- }
- }
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- switch currentSearchType {
- case .menuItems:
- let cell = tableView.dequeueReusableCell(withIdentifier: "ItemCell") as! SearchItemCell
- cell.configure(item: menuItemResults[indexPath.row])
- return cell
- case .restaurants:
- let cell = tableView.dequeueReusableCell(withIdentifier: "RestaurantCell") as! RestaurantCell
- cell.configure(restaurant: restaurantResults[indexPath.row])
- return cell
- }
- }
- }
- class SearchItemCell: UITableViewCell {
- …
- var ratingPie: PieChart!
- var ratingPieLabel: UILabel!
- required init(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)!
- }
- override init(style: UITableViewCellStyle, reuseIdentifier: String!) {
- super.init(style: style, reuseIdentifier: reuseIdentifier)
- ratingPie = PieChart()
- ratingPie.layers = []
- …
- […, ratingPie, …].forEach {
- contentView.addSubview($0)
- }
- ratingPieLabel = UILabel()
- [ratingPieLabel].forEach {
- ratingPie.addSubview($0)
- }
- …
- ratingPie.anchor(top: nil, leading: nil, bottom: bottomAnchor, trailing: trailingAnchor,
- padding: .init(top: 0, left: 0, bottom: 16, right: 8),
- size: .init(width: 40.0, height: 40))
- ratingPie.animDuration = 0
- ratingPie.referenceAngle=210
- ratingPie.innerRadius=14
- ratingPie.outerRadius=18
- ratingPieLabel.anchorCenter(to: ratingPie)
- ratingPieLabel.font = UIFont(name: StyleKit.Font.regular, size: 10)
- func configure(item: MenuItem) {
- if item.overallRating > 0{
- ratingPie.isHidden = false
- ratingPieLabel.isHidden = false
- ratingPie.models = [PieSliceModel(value: (1-item.overallRating)*10, color: .lightGray),
- PieSliceModel(value: item.overallRating*10, color: .green)]
- ratingPieLabel.text = String(format: "%.0f", item.overallRating * 100)
- } else{
- ratingPie.isHidden = true
- ratingPieLabel.isHidden = true
- }
- …
- }
- }
Add Comment
Please, Sign In to add comment