@@ -18,108 +18,133 @@ class CustomActionSheetFilterVC: UIViewController {
18
18
@IBOutlet weak var categoryLabel : UILabel !
19
19
// 서버통신을 통해 받아오는 값
20
20
var categoryArray : [ ExploreCategory ] = [ ]
21
- // all, public, unpublic
22
- var availablityArray : [ Bool ] = [ false , false , false ]
23
- private var filterCVCDelegate : FilterCVCDelegate ?
21
+ // private var filterCVCDelegate: FilterCVCDelegate?
24
22
var fromServer = true
25
- var categorySelected : Int = 0
26
- private var selectedAvailablity : String = " all "
23
+
24
+ private var selectedCategory : Int ?
25
+ = nil
26
+
27
+ private var selectedAvailablity : String ? = nil
28
+
27
29
override func viewDidLoad( ) {
28
30
super. viewDidLoad ( )
29
31
setLabel ( )
30
32
setButton ( view: allButton, isSelected: false )
31
33
setButton ( view: publicButton, isSelected: false )
32
34
setButton ( view: unpublicButton, isSelected: false )
33
35
34
-
36
+ categoryCollectionView . showsHorizontalScrollIndicator = false
35
37
categoryCollectionView. delegate = self
36
38
categoryCollectionView. dataSource = self
37
-
38
- selectedAvailablity = " all "
39
- allButton. backgroundColor = . black
40
- allButton. setTitleColor ( . white, for: . normal)
41
- allButton. setBorderWithRadius ( borderColor: . black, borderWidth: 1 , cornerRadius: 4 )
42
-
43
- publicButton. backgroundColor = . white
44
- publicButton. setTitleColor ( . slateGrey, for: . normal)
45
- publicButton. setBorderWithRadius ( borderColor: . veryLightPink, borderWidth: 1 , cornerRadius: 4 )
46
-
47
- unpublicButton. backgroundColor = . white
48
- unpublicButton. setTitleColor ( . slateGrey, for: . normal)
49
- unpublicButton. setBorderWithRadius ( borderColor: . veryLightPink, borderWidth: 1 , cornerRadius: 4 )
50
-
51
-
52
- // Do any additional setup after loading the view.
39
+
40
+ availablityButtonSet ( availablity: selectedAvailablity)
53
41
}
54
42
55
43
override func viewWillAppear( _ animated: Bool ) {
56
44
45
+ // getSelectedFilterInfo()
57
46
setCategoryData ( )
47
+ selectedAvailablity = MypageVC . selectedAvailablity
48
+ selectedCategory = MypageVC . selectedCategory
49
+ availablityButtonSet ( availablity: selectedAvailablity)
58
50
}
59
51
52
+
60
53
@IBAction func dismissButtonTapped( _ sender: UIButton ) {
61
54
NotificationCenter . default. post ( name: . init( " categoryClose " ) , object: nil )
62
55
self . dismiss ( animated: true , completion: nil )
63
56
}
64
57
65
58
@IBAction func allButtonTapped( _ sender: UIButton ) {
66
59
selectedAvailablity = " all "
67
- allButton. backgroundColor = . black
68
- allButton. setTitleColor ( . white, for: . normal)
69
- allButton. setBorderWithRadius ( borderColor: . black, borderWidth: 1 , cornerRadius: 4 )
70
-
71
- publicButton. backgroundColor = . white
72
- publicButton. setTitleColor ( . slateGrey, for: . normal)
73
- publicButton. setBorderWithRadius ( borderColor: . veryLightPink, borderWidth: 1 , cornerRadius: 4 )
74
-
75
- unpublicButton. backgroundColor = . white
76
- unpublicButton. setTitleColor ( . slateGrey, for: . normal)
77
- unpublicButton. setBorderWithRadius ( borderColor: . veryLightPink, borderWidth: 1 , cornerRadius: 4 )
60
+ availablityButtonSet ( availablity: selectedAvailablity)
78
61
}
79
62
80
63
@IBAction func publicButtonTapped( _ sender: UIButton ) {
81
64
selectedAvailablity = " public "
82
- allButton. backgroundColor = . white
83
- allButton. setTitleColor ( . slateGrey, for: . normal)
84
- allButton. setBorderWithRadius ( borderColor: . veryLightPink, borderWidth: 1 , cornerRadius: 4 )
85
-
86
- publicButton. backgroundColor = . black
87
- publicButton. setTitleColor ( . white, for: . normal)
88
- publicButton. setBorderWithRadius ( borderColor: . black, borderWidth: 1 , cornerRadius: 4 )
89
-
90
-
91
-
92
- unpublicButton. backgroundColor = . white
93
- unpublicButton. setTitleColor ( . slateGrey, for: . normal)
94
- unpublicButton. setBorderWithRadius ( borderColor: . veryLightPink, borderWidth: 1 , cornerRadius: 4 )
95
-
65
+ availablityButtonSet ( availablity: selectedAvailablity)
96
66
}
97
67
@IBAction func unpublicButtonTapped( _ sender: UIButton ) {
98
-
99
68
selectedAvailablity = " unpublic "
100
- allButton. backgroundColor = . white
101
- allButton. setTitleColor ( . slateGrey, for: . normal)
102
- allButton. setBorderWithRadius ( borderColor: . veryLightPink, borderWidth: 1 , cornerRadius: 4 )
103
-
104
- publicButton. backgroundColor = . white
105
- publicButton. setTitleColor ( . slateGrey, for: . normal)
106
- publicButton. setBorderWithRadius ( borderColor: . veryLightPink, borderWidth: 1 , cornerRadius: 4 )
107
-
108
-
109
- unpublicButton. backgroundColor = . black
110
- unpublicButton. setTitleColor ( . white, for: . normal)
111
- unpublicButton. setBorderWithRadius ( borderColor: . black, borderWidth: 1 , cornerRadius: 4 )
112
-
69
+ availablityButtonSet ( availablity: selectedAvailablity)
113
70
}
114
71
115
- private func selectPrivate( _ sender: UIButton ) {
116
-
117
-
118
- }
72
+
119
73
@IBAction func applyButtonTapped( _ sender: Any ) {
120
74
121
- NotificationCenter . default. post ( name: . init( " categoryClose " ) , object: nil , userInfo: [ " categoryId " : categorySelected + 1 , " selectedAv " : selectedAvailablity] )
75
+ NotificationCenter . default. post ( name: . init( " categoryClose " ) , object: nil , userInfo: [ " categoryId " : selectedCategory , " selectedAv " : selectedAvailablity ?? " all " ] )
122
76
self . dismiss ( animated: true , completion: nil )
77
+
78
+ }
79
+
80
+ // @objc func getSelectedFilterInfo(_ notification: Notification) {
81
+ // guard let userInfo = notification.userInfo as? [String: Any] else { return }
82
+ // guard let categoryId = userInfo["categoryId"] as? Int else { return }
83
+ // guard let selectedAv = userInfo["selectedAv"] as? String else { return }
84
+ //
85
+ // self.selectedAvailablity = selectedAv
86
+ // self.selectedCategory = categoryId
87
+ //
88
+ // }
89
+ // func categoryButtonSet(category: Int){
90
+ // <#function body#>
91
+ // }
92
+ func availablityButtonSet( availablity: String ? ) {
93
+ switch availablity {
94
+ case " all " :
95
+ allButton. backgroundColor = . black
96
+ allButton. setTitleColor ( . white, for: . normal)
97
+ allButton. setBorderWithRadius ( borderColor: . black, borderWidth: 1 , cornerRadius: 4 )
98
+
99
+ publicButton. backgroundColor = . white
100
+ publicButton. setTitleColor ( . slateGrey, for: . normal)
101
+ publicButton. setBorderWithRadius ( borderColor: . veryLightPink, borderWidth: 1 , cornerRadius: 4 )
102
+
103
+ unpublicButton. backgroundColor = . white
104
+ unpublicButton. setTitleColor ( . slateGrey, for: . normal)
105
+ unpublicButton. setBorderWithRadius ( borderColor: . veryLightPink, borderWidth: 1 , cornerRadius: 4 )
106
+
107
+ case " public " :
108
+ allButton. backgroundColor = . white
109
+ allButton. setTitleColor ( . slateGrey, for: . normal)
110
+ allButton. setBorderWithRadius ( borderColor: . veryLightPink, borderWidth: 1 , cornerRadius: 4 )
111
+
112
+ publicButton. backgroundColor = . black
113
+ publicButton. setTitleColor ( . white, for: . normal)
114
+ publicButton. setBorderWithRadius ( borderColor: . black, borderWidth: 1 , cornerRadius: 4 )
115
+
116
+
117
+
118
+ unpublicButton. backgroundColor = . white
119
+ unpublicButton. setTitleColor ( . slateGrey, for: . normal)
120
+ unpublicButton. setBorderWithRadius ( borderColor: . veryLightPink, borderWidth: 1 , cornerRadius: 4 )
121
+ case " unpublic " :
122
+ allButton. backgroundColor = . white
123
+ allButton. setTitleColor ( . slateGrey, for: . normal)
124
+ allButton. setBorderWithRadius ( borderColor: . veryLightPink, borderWidth: 1 , cornerRadius: 4 )
125
+
126
+ publicButton. backgroundColor = . white
127
+ publicButton. setTitleColor ( . slateGrey, for: . normal)
128
+ publicButton. setBorderWithRadius ( borderColor: . veryLightPink, borderWidth: 1 , cornerRadius: 4 )
129
+
130
+
131
+ unpublicButton. backgroundColor = . black
132
+ unpublicButton. setTitleColor ( . white, for: . normal)
133
+ unpublicButton. setBorderWithRadius ( borderColor: . black, borderWidth: 1 , cornerRadius: 4 )
134
+
135
+ default :
136
+ allButton. backgroundColor = . black
137
+ allButton. setTitleColor ( . white, for: . normal)
138
+ allButton. setBorderWithRadius ( borderColor: . black, borderWidth: 1 , cornerRadius: 4 )
139
+
140
+ publicButton. backgroundColor = . white
141
+ publicButton. setTitleColor ( . slateGrey, for: . normal)
142
+ publicButton. setBorderWithRadius ( borderColor: . veryLightPink, borderWidth: 1 , cornerRadius: 4 )
143
+
144
+ unpublicButton. backgroundColor = . white
145
+ unpublicButton. setTitleColor ( . slateGrey, for: . normal)
146
+ unpublicButton. setBorderWithRadius ( borderColor: . veryLightPink, borderWidth: 1 , cornerRadius: 4 )
147
+ }
123
148
}
124
149
125
150
func setLabel( ) {
@@ -146,7 +171,7 @@ class CustomActionSheetFilterVC: UIViewController {
146
171
147
172
extension CustomActionSheetFilterVC : UICollectionViewDelegate {
148
173
func collectionView( _ collectionView: UICollectionView , didSelectItemAt indexPath: IndexPath ) {
149
- categorySelected = indexPath. item
174
+ selectedCategory = indexPath. item
150
175
151
176
}
152
177
}
@@ -163,9 +188,22 @@ extension CustomActionSheetFilterVC: UICollectionViewDataSource {
163
188
for: indexPath) as? FilterCVC else {
164
189
return UICollectionViewCell ( ) }
165
190
cell. indexPath = indexPath. row
191
+
166
192
cell. category = self . categoryArray [ indexPath. item]
167
- cell . filterCVCDelegate = self
193
+
168
194
cell. setButton ( text: categoryArray [ indexPath. item] . name)
195
+
196
+ // if selectedCategory != nil {
197
+ // if self.categoryArray[indexPath.item].id == selectedCategory!+1 {
198
+ // cell.setButton(selected: true)
199
+ // }
200
+ // } else {
201
+ //
202
+ // }
203
+
204
+
205
+ // cell.filterCVCDelegate = self
206
+
169
207
170
208
return cell
171
209
@@ -181,7 +219,7 @@ extension CustomActionSheetFilterVC: UICollectionViewDataSource {
181
219
}
182
220
183
221
if cell. isSelected {
184
- categorySelected = 0
222
+ selectedCategory = 0
185
223
collectionView. deselectItem ( at: indexPath, animated: false )
186
224
return false
187
225
} else {
@@ -233,10 +271,10 @@ extension CustomActionSheetFilterVC {
233
271
}
234
272
}
235
273
}
236
-
237
- extension CustomActionSheetFilterVC : FilterCVCDelegate {
238
- func setSelectedCategory( index: Int ) {
239
-
240
- }
241
-
242
- }
274
+ //
275
+ // extension CustomActionSheetFilterVC: FilterCVCDelegate {
276
+ // func setSelectedCategory(index: Int) {
277
+ //
278
+ // }
279
+ //
280
+ // }
0 commit comments