-
Notifications
You must be signed in to change notification settings - Fork 0
/
InfosWithTableCell.swift
279 lines (218 loc) · 9.72 KB
/
InfosWithTableCell.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
//
// InfosWithTableCell.swift
// VistaBridge
//
// Created by 齐晴 on 16/9/21.
// Copyright © 2016年 GaryQi. All rights reserved.
//
import UIKit
class InfosWithTableCell: UICollectionViewCell, UITableViewDataSource, UITableViewDelegate{
@IBOutlet weak var typeLabel: UILabel!
@IBOutlet weak var infosTable: UITableView!
var identifierNo = -1 //代表要创建的cell的identifier在数组identifiersOfTableViewCell的位置
let identifiersOfTableViewCell = [
"CastActorInfoCell",
"BackgroundActorInfoCell",
"BackgroundActorInfoCell",
"BackgroundActorInfoCell"
]
var castActorInfos : [CharacterInfosAboutScene] = [] {
didSet{
//如果castActorInfos被赋值,说明tableview要显示的是主要演员的信息
identifierNo = 0
infosTable.reloadData()
}
}
var backgroundActorInfos : [BackgroundcharacterInfosAboutScene] = [] {
didSet{
//如果backgroundActorInfos被赋值,说明tableview要显示的是群众演员的信息
identifierNo = 1
infosTable.reloadData()
}
}
var props : [PropsAboutScene] = [] {
didSet {
//如果prps被赋值,说明tableview要显示的是道具的信息
identifierNo = 2
infosTable.reloadData()
}
}
var equipmentInfos : [EquipmentInfosAboutScene] = [] {
didSet {
//如果equpiments被赋值,说明tableview要显示的是拍摄器械的信息
identifierNo = 3
infosTable.reloadData()
}
}
func prepareInfosWithTableCell(_ typeOfTheCell : TypeOfTheCommonInfos , sceneNo : Int) {
infosTable.dataSource = self
infosTable.delegate = self
//infosTable的分割线,滑动指示器
infosTable.separatorStyle = .none
infosTable.showsVerticalScrollIndicator = false
switch typeOfTheCell {
case .cast :
//主要演员cell
//获得该场次的所有涉及的主演信息
castActorInfos = searchCastActorInfosBySceneNo(sceneNo)
case .background :
//群众演员cell
//获得该场次的所有涉及的群演信息
backgroundActorInfos = searchBackgroundInfosBySceneNo(sceneNo)
case .props :
//涉及道具cell
//获得该场次涉及道具的信息
props = searchPropsInfosBySceneNo(sceneNo)
case .equipment :
//拍摄器械信息Cell
equipmentInfos = searchEquipmentInfosBySceneNo(sceneNo)
default:
print("还没有写其它的")
}
}
func prepareInfosWithTableCell() {
infosTable.dataSource = self
infosTable.delegate = self
infosTable.reloadData()
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
switch identifierNo {
case 0 :
return castActorInfos.count
case 1 :
return backgroundActorInfos.count
case 2 :
return props.count
case 3:
return equipmentInfos.count
default:
print("还没有写其它的")
return 0
}
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch identifierNo {
case -1:
print("还没有写其它的")
let cell = tableView.dequeueReusableCell(withIdentifier: identifiersOfTableViewCell[1]) as! BackgroundActorInfoCell
return cell
case 0:
//主要演员cell
let cell = tableView.dequeueReusableCell(withIdentifier: identifiersOfTableViewCell[identifierNo]) as! CastActorInfoCell
cell.actorNameLabel.text = searchCastActorNameByID(castActorInfos[indexPath.row].characterID)
// cell.actorMakeupButton.setImage(UIImage?, forState: UIControlState) 设置演员化妆的Button
// cell.actorWardrobeButton.setImage(UIImage?, forState: UIControlState) 设置演员服装的Button
return cell
case 1:
//群众演员cell
let cell = tableView.dequeueReusableCell(withIdentifier: identifiersOfTableViewCell[identifierNo]) as! BackgroundActorInfoCell
cell.backgroundActorNameLabel.text = searchBackgroundActorNameByID(backgroundActorInfos[indexPath.row].backgroundCharacterID)
cell.numberLabel.text = "X \(backgroundActorInfos[indexPath.row].number)"
return cell
case 2:
//道具Cell,目前先复用群众演员的CELL类吧
let cell = tableView.dequeueReusableCell(withIdentifier: identifiersOfTableViewCell[identifierNo]) as! BackgroundActorInfoCell
cell.backgroundActorNameLabel.text = searchPropsNameByID(props[indexPath.row].propsID)
cell.numberLabel.text = "X \(props[indexPath.row].number)"
return cell
case 3:
//器械Cell,目前先服用群众演员的CELLL类吧
let cell = tableView.dequeueReusableCell(withIdentifier: identifiersOfTableViewCell[identifierNo]) as! BackgroundActorInfoCell
cell.backgroundActorNameLabel.text = searchEquipmentNameByID(equipmentInfos[indexPath.row].equipmentID)
cell.numberLabel.text = "X \(equipmentInfos[indexPath.row].number)"
return cell
default :
print("还没有写其它的")
let cell = tableView.dequeueReusableCell(withIdentifier: identifiersOfTableViewCell[identifierNo]) as! BackgroundActorInfoCell
return cell
}
}
fileprivate func searchCastActorInfosBySceneNo(_ sceneNo : Int) -> [CharacterInfosAboutScene]{
//搜寻该场次的设计主演信息
//ps. 忽出鲁 1号妆, 1号装 ["忽出鲁",1,1]
var castActorInfosAboutScene : [CharacterInfosAboutScene] = []
// var castActorInfosAboutScene : [SceneInfo] = []
// for castActorInfo in CASTACTOR_INFOS_ABOUT_SCENE {
// if castActorInfo.sceneNo == sceneNo {
// castActorInfosAboutScene.append(castActorInfo)
// }
// }
for sceneInfo in SCENE_INFOS {
if sceneInfo.sceneNo.number == sceneNo {
if (sceneInfo.characters != nil) {
for character in sceneInfo.characters! {
let castActorInfo = CharacterInfosAboutScene(characterID: character.ID, sceneNo: sceneNo, characterMakeupID: character.makeups![0].makeupID, characterWardrobeID: character.wardrobes[0].wardrobeID)
castActorInfosAboutScene.append(castActorInfo)
}
}
}
}
return castActorInfosAboutScene
}
fileprivate func searchCastActorNameByID(_ characterID : Int) -> String {
for character in characters {
if character.ID == characterID {
return character.name
}
}
print("InfosWithTableCell_searchCastActorNameByID_没有找到")
return ""
}
fileprivate func searchBackgroundInfosBySceneNo(_ sceneNo : Int) -> [BackgroundcharacterInfosAboutScene] {
var backgroundActorInfosAboutScene : [BackgroundcharacterInfosAboutScene] = []
for backgroundActor in BACKGROUND_ACTORS_INFOS_ABOUT_SCENE {
if backgroundActor.sceneNo == sceneNo {
backgroundActorInfosAboutScene.append(backgroundActor)
}
}
return backgroundActorInfosAboutScene
}
fileprivate func searchBackgroundActorNameByID(_ backgroundActorID : Int) -> String {
for backgroundActor in BACKGROUND_ACTORS_INFOS {
if backgroundActor.ID == backgroundActorID {
return backgroundActor.name
}
}
print("InfosWithTableCell_searchBackgroundActorNameByID_没有找到")
return ""
}
fileprivate func searchPropsInfosBySceneNo(_ sceneNo : Int) -> [PropsAboutScene] {
var propsAboutScene : [PropsAboutScene] = []
for propsInfo in PROPS_INFOS_ABOUT_SCENE {
if propsInfo.sceneNo == sceneNo {
propsAboutScene.append(propsInfo)
}
}
return propsAboutScene
}
fileprivate func searchPropsNameByID(_ propsID : Int) -> String {
for props in PROPS {
if props.propsID == propsID {
return props.name
}
}
print("InfosWithTableCell_searchPropsNameByID_没有找到")
return ""
}
fileprivate func searchEquipmentInfosBySceneNo(_ sceneNo : Int) -> [EquipmentInfosAboutScene] {
var equipmentInfos : [EquipmentInfosAboutScene] = []
for equipment in EQUIPMENTS_INFOS_ABOUT_SCENE {
if equipment.sceneNo == sceneNo {
equipmentInfos.append(equipment)
}
}
return equipmentInfos
}
fileprivate func searchEquipmentNameByID(_ equipmentID : Int) -> String {
for equipment in EQUIPMENTS {
if equipment.equipmentID == equipmentID {
return equipment.name
}
}
print("InfosWithTableCell_searchEquipmentNameByID_没有找到")
return ""
}
}