0
なぜ実際のアーティスト名のテーブルビューではなく、「アーティスト」でいっぱいのテーブルビューに次の結果が出るのですか?どこで私は間違えましたか?アーティストの価値をコレクションから引き出すにはどうすればよいですか?すべてのヘルプは...MPMediaItemCollectionからアーティスト値を引き出す方法
var tableData = MPMediaQuery.artistsQuery()
override func viewDidLoad() {
super.viewDidLoad()
self.artistTableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell")
tableData.groupingType = MPMediaGrouping.Artist
}
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: 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
}
これはうまくいきました...ありがとう! – rocketman240
xcodeは私に(tableData.collections?)のようなことを強いる!これはもっと良いですか? – rocketman240
@ rocketman240あなたはオプションのバインディングを使用するか、 'guard'をチェックして' tableData.collections'がnilでないことを確認します。例えば 'let let collections = tableData.collections {//前と同じように処理する}'または 'guard let collections = tableData.collections else {// else else}' – Wes