This repository was archived by the owner on Oct 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRatingTableViewController.swift
138 lines (113 loc) · 5.01 KB
/
RatingTableViewController.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//
// RatingTableViewController.swift
// mec-wheel
//
// Created by jason on 1/19/17.
// Copyright © 2017 jason. All rights reserved.
//
import UIKit
class RatingTableViewController: UITableViewController {
@IBOutlet weak var chcRating: UILabel!
@IBOutlet weak var popRating: UILabel!
@IBOutlet weak var dmpaRating: UILabel!
@IBOutlet weak var implantsRating: UILabel!
@IBOutlet weak var lngiudRating: UILabel!
@IBOutlet weak var cuiudRating: UILabel!
@IBOutlet weak var chcCell: UITableViewCell!
@IBOutlet weak var popCell: UITableViewCell!
@IBOutlet weak var dmpaCell: UITableViewCell!
@IBOutlet weak var implantsCell: UITableViewCell!
@IBOutlet weak var lngiudCell: UITableViewCell!
@IBOutlet weak var cuiudCell: UITableViewCell!
var notesForSelectedCell: [Note] = []
var currentCondition = Condition()
var chc, pop, dmpa, implants, lngiud, cuiud: Rating?
override func viewDidLoad() {
super.viewDidLoad()
switch sharedConditionContent.currentRatingType {
case "Initiation":
chc = currentCondition.chcInitiation!
pop = currentCondition.popInitiation!
dmpa = currentCondition.dmpaInitiation!
implants = currentCondition.implantsInitiation!
lngiud = currentCondition.lngiudInitiation!
cuiud = currentCondition.cuiudInitiation!
case "Continuation":
chc = currentCondition.chcContinuation!
pop = currentCondition.popContinuation!
dmpa = currentCondition.dmpaContinuation!
implants = currentCondition.implantsContinuation!
lngiud = currentCondition.lngiudContinuation!
cuiud = currentCondition.cuiudContinuation!
default:
break
}
chcRating.attributedText = getRatingWithNotesSymbols(rating: chc!)
popRating.attributedText = getRatingWithNotesSymbols(rating: pop!)
dmpaRating.attributedText = getRatingWithNotesSymbols(rating: dmpa!)
implantsRating.attributedText = getRatingWithNotesSymbols(rating: implants!)
lngiudRating.attributedText = getRatingWithNotesSymbols(rating: lngiud!)
cuiudRating.attributedText = getRatingWithNotesSymbols(rating: cuiud!)
chcCell.isUserInteractionEnabled = chc?.notes != nil
popCell.isUserInteractionEnabled = pop?.notes != nil
dmpaCell.isUserInteractionEnabled = dmpa?.notes != nil
implantsCell.isUserInteractionEnabled = implants?.notes != nil
lngiudCell.isUserInteractionEnabled = lngiud?.notes != nil
cuiudCell.isUserInteractionEnabled = cuiud?.notes != nil
}
func getRatingWithNotesSymbols(rating: Rating) -> NSMutableAttributedString {
let fontSuper:UIFont? = UIFont(name: "Helvetica", size:10)
var notesSymbols = ""
if rating.notes != nil {
for note in rating.notes! {
notesSymbols += note.name
}
}
if rating.rating == "" {
return NSMutableAttributedString(string: notesSymbols)
}
let returnString = NSMutableAttributedString(string: rating.rating)
let symbolsString = NSMutableAttributedString(string: notesSymbols)
symbolsString.setAttributes([NSAttributedString.Key.font:fontSuper!,NSAttributedString.Key.baselineOffset:8], range: NSRange(location: 0, length: symbolsString.length))
returnString.append(symbolsString)
return returnString
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
switch indexPath.row {
case 0:
notesForSelectedCell = (chc?.notes)!
case 1:
notesForSelectedCell = (pop?.notes)!
case 2:
notesForSelectedCell = (dmpa?.notes)!
case 3:
notesForSelectedCell = (implants?.notes)!
case 4:
notesForSelectedCell = (lngiud?.notes)!
case 5:
notesForSelectedCell = (cuiud?.notes)!
default:
break
}
performSegue(withIdentifier: "MethodNotesSegue", sender: UITableViewCell.self)
}
// MARK: - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// Get the new view controller using segue.destinationViewController.
// Pass the selected object to the new view controller.
guard let vc = segue.destination as? NoteDetailViewController else {
fatalError("error")
}
switch segue.identifier {
case "MethodNotesSegue"?:
vc.notes = notesForSelectedCell
default:
break
}
}
}