2015-01-11 2 views
0

그것은 오디오 재생 목록스위프트 - jQuery과

을 변경하는 방법
import UIKit 
import MediaPlayer 

class TableView: UIViewController, UITableViewDelegate, UITableViewDataSource { 

@IBOutlet var tableView: UITableView! 

var tableData = MPMediaQuery.playlistsQuery() 

override func viewDidLoad() { 
    super.viewDidLoad() 


    self.tableView.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell") 

    self.tableView.reloadData() 

} 

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
return self.tableData.collections.count 
} 

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell  { 

    var cell: UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell 

    let playlist: MPMediaPlaylist = tableData.collections[indexPath.row] as MPMediaPlaylist 
    let playlistName = playlist.valueForProperty(MPMediaPlaylistPropertyName) as NSString 
    cell.textLabel?.text = playlistName 

    return cell 
} 

func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) { 
    println("Row \(indexPath.row) selected") 
} 
} 

에 대한 jQuery과 인,의 TableView의 앨범을 가지고? 0x1002364b0 :

내가 var tableData = MPMediaQuery.albumsQuery()

var tableData = MPMediaQuery.playlistsQuery()

을 변경 tryed하지만 정확하지 않은, 엑스 코드는 나에게 오류 제공 BRK 번호를 1

+4

tableView의 위임을 할당 한 곳을 확인하십시오 (Interface Builder?). 보기 컨트롤러가 아닌 UIView 인스턴스로 설정됩니다. – Paulw11

답변

0

무슨 짓을하는 것은 변화, 좋은 시작이다 tableData의 결과는 MPMediaQuery.playlistsQuery 대신 MPMediaQuery.albumsQuery이됩니다.

let playlist: MPMediaPlaylist = tableData.collections[indexPath.row] as MPMediaPlaylist 
let playlistName = playlist.valueForProperty(MPMediaPlaylistPropertyName) as NSString 
cell.textLabel?.text = playlistName 

이 코드는 tableDataMPMediaPlaylist 객체를 포함한 컬렉션 속성에 포함 된 것으로 예상하지만 MPMediaQuery.albumsQuery 방법은 MPMediaQuery 객체를 반환 : 그러나, 당신의 cellForRowAtIndexPath 방법에서 각 셀의 내용을 정의 특히 다음 세 줄을 보면 MPMediaItem 개체를 포함하는 collections 속성을 사용합니다.