【发布时间】:2014-12-01 19:23:56
【问题描述】:
主要作用是在表格视图中显示播放列表名称,但它在大约 500 个单元格中显示单词“名称”!
我可以犯一个简单的错误,因为我只学习 swift,它是我的第一门编程语言
有代码:
import UIKit
import MediaPlayer
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet var tableView: UITableView!
var tableData = MPMediaQuery.playlistsQuery()
var songname: NSString = MPMediaPlaylistPropertyName
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.items.count
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell: UITableViewCell = self.tableView.dequeueReusableCellWithIdentifier("cell") as UITableViewCell
cell.textLabel.text = songname
return cell
}
func tableView(tableView: UITableView!, didSelectRowAtIndexPath indexPath: NSIndexPath!) {
println("Row \(indexPath.row) selected")
}
}
【问题讨论】:
-
您不会根据索引路径为单元格设置不同的文本。
标签: iphone xcode uitableview swift audio-player