質問編集履歴
2
さらに追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -276,9 +276,15 @@
|
|
276
276
|
|
277
277
|
``Artist Collection``をIBOutletで接続しており、
|
278
278
|
|
279
|
-
その中の``Collection Reusable View``はIdentifierを``"HeaderView"``にしてあり、
|
279
|
+
その中の``Collection Reusable View``はIdentifierを``"HeaderView"``にしてあり、
|
280
|
+
|
280
|
-
|
281
|
+
``sectionName``ラベルはtagを1にしてあります。
|
282
|
+
|
283
|
+
``Cell``の方はIdentifierを``"Cell"``にしてありますが、
|
284
|
+
|
281
|
-
|
285
|
+
中の``ArtistName``ラベルは特に何も接続していませんし、tagもIdentifierもいじっていません(それもいけないんでしょうか・・・)
|
286
|
+
|
287
|
+
ちなみに、``Cell``はstoryboard上で横幅を341pxに、縦を100pxにしてあります。iPadのランドスケープで3カラムにすることを想定しています。
|
282
288
|
|
283
289
|
|
284
290
|
|
1
詳細のコード、storyboardの追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -130,6 +130,158 @@
|
|
130
130
|
|
131
131
|
|
132
132
|
|
133
|
+
###追記
|
134
|
+
|
135
|
+
sectionの宣言部分を、とのことでしたが、どちらの部分かわからなかったため、全文を載せさせていただきます。
|
136
|
+
|
137
|
+
```swift
|
138
|
+
|
139
|
+
class ArtistTabView: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
@IBOutlet weak var artistCollection: UICollectionView!
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
var sectionData = Array<MPMediaQuerySection>()
|
148
|
+
|
149
|
+
var artistData = Array<MPMediaItemCollection>()
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
override func viewDidLoad() {
|
154
|
+
|
155
|
+
super.viewDidLoad()
|
156
|
+
|
157
|
+
// Do any additional setup after loading the view, typically from a nib.
|
158
|
+
|
159
|
+
artistCollection.delegate = self
|
160
|
+
|
161
|
+
artistCollection.dataSource = self
|
162
|
+
|
163
|
+
sectionData = getSectionInfo()
|
164
|
+
|
165
|
+
artistData = getArtistInfo()
|
166
|
+
|
167
|
+
}
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
override func didReceiveMemoryWarning() {
|
172
|
+
|
173
|
+
super.didReceiveMemoryWarning()
|
174
|
+
|
175
|
+
// Dispose of any resources that can be recreated.
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
func getSectionInfo() -> Array<MPMediaQuerySection> {
|
182
|
+
|
183
|
+
var sectionArray = Array<MPMediaQuerySection>()
|
184
|
+
|
185
|
+
let artistQuery: MPMediaQuery = MPMediaQuery.artists()
|
186
|
+
|
187
|
+
let artistSection = artistQuery.collectionSections!
|
188
|
+
|
189
|
+
sectionArray = artistSection
|
190
|
+
|
191
|
+
return sectionArray
|
192
|
+
|
193
|
+
}
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
func getArtistInfo() -> Array<MPMediaItemCollection> {
|
198
|
+
|
199
|
+
var artistArray = Array<MPMediaItemCollection>()
|
200
|
+
|
201
|
+
let artistQuery: MPMediaQuery = MPMediaQuery.artists()
|
202
|
+
|
203
|
+
let artistCollection = artistQuery.collections!
|
204
|
+
|
205
|
+
artistArray = artistCollection
|
206
|
+
|
207
|
+
return artistArray
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
internal func numberOfSections(in collectionView: UICollectionView) -> Int {
|
216
|
+
|
217
|
+
return self.sectionData.count
|
218
|
+
|
219
|
+
}
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
224
|
+
|
225
|
+
return self.sectionData[section].range.length
|
226
|
+
|
227
|
+
}
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
|
232
|
+
|
233
|
+
var reusableView = UICollectionReusableView()
|
234
|
+
|
235
|
+
if kind == UICollectionElementKindSectionHeader {
|
236
|
+
|
237
|
+
let headerView = collectionView.dequeueReusableSupplementaryView(ofKind: UICollectionElementKindSectionHeader, withReuseIdentifier: "HeaderView", for: indexPath)
|
238
|
+
|
239
|
+
if let label = headerView.viewWithTag(1) as? UILabel {
|
240
|
+
|
241
|
+
label.text = sectionData[section].title
|
242
|
+
|
243
|
+
}
|
244
|
+
|
245
|
+
reusableView = headerView
|
246
|
+
|
247
|
+
}
|
248
|
+
|
249
|
+
return reusableView
|
250
|
+
|
251
|
+
}
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
256
|
+
|
257
|
+
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath)
|
258
|
+
|
259
|
+
let collection = self.artistData[section.range.location + indexPath.row]
|
260
|
+
|
261
|
+
cell.textLabel?.text = collection.representativeItem?.artist
|
262
|
+
|
263
|
+
return cell
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
}
|
270
|
+
|
271
|
+
```
|
272
|
+
|
273
|
+
ちなみに、storyboardはこんな感じです。
|
274
|
+
|
275
|
+
![こんなかんじ](b1efbc3c9857641fba3db542a6738340.png)
|
276
|
+
|
277
|
+
``Artist Collection``をIBOutletで接続しており、
|
278
|
+
|
279
|
+
その中の``Collection Reusable View``はIdentifierを``"HeaderView"``にしてあり、``sectionName``ラベルはtagを1にしてあります。
|
280
|
+
|
281
|
+
``Cell``の方はIdentifierを``"Cell"``にしてありますが、中の``ArtistName``ラベルは特に何も接続していませんし、tagもIdentifierもいじっていません(それもいけないんでしょうか・・・)
|
282
|
+
|
283
|
+
|
284
|
+
|
133
285
|
###補足情報(言語/FW/ツール等のバージョンなど)
|
134
286
|
|
135
287
|
xcode8 swift3
|