ここで非常に基本的な何かが欠けている可能性が非常に高いことはわかっていますが、行き詰まっています。次のコードは、グループにリストされたアーティストではなく、各トラックのアーティストのテーブル ビューを生成するのはなぜですか (つまり、各アーティストが 1 回だけリストされるように、すべてグループ化されるのではなく、各アーティストが 20 回ほどリストされるのはなぜですか)。以下で説明するコレクションとアイテムの両方のバージョンを試しました。私は何を間違っていますか?これを修正するにはどうすればよいですか? どんな助けでも大歓迎です。前もって感謝します...
var tableData = MPMediaQuery.artistsQuery()
override func viewDidLoad() {
super.viewDidLoad()
self.artistTableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.tableData.collections!.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell: UITableViewCell = self.artistTableView.dequeueReusableCellWithIdentifier("cell")! as UITableViewCell
let artist: MPMediaItem = tableData.items![indexPath.row]
//let artist: MPMediaItemCollection = tableData.collections![indexPath.row]
if artist.valueForProperty(MPMediaItemPropertyArtist) == nil {
cell.textLabel?.text = "Artist" as String
} else {
let artistName = artist.valueForProperty(MPMediaItemPropertyArtist) as! NSString
cell.textLabel?.text = artistName as String
}
return cell
}