【发布时间】:2016-04-26 07:05:50
【问题描述】:
我有一个 UITableView 使用自定义单元格,其中填充了 MPMediaItems 和按钮(以及其他内容)。我正在尝试使用特定单元格的 MPMediaItem 执行操作,而不是通过 didSelectRowAtIndexPath 来点击哪个按钮。我尝试了各种方法,我相信标签可能是要走的路,但我无法得到正确的实现。我似乎只能得到该系列的第一项或最后一项。处理 MPMediaItems 时设置标签的正确方法是什么?下面是一些代码...
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
let cell : SongCell = self.songsTableView.dequeueReusableCellWithIdentifier("cell") as! SongCell
cell.button.addTarget(self, action: #selector(handleSelection), forControlEvents: .TouchUpInside)
cell.tag = indexPath.row //removing this line results in getting the first item in the collection, using it results in the last (understandably so)
index = cell.tag
return cell
}
@IBAction func handleSelection(sender: AnyObject)
{
let songToHandle = tableData.items![index!]
queryAsCollectionItems?.append()
}
【问题讨论】:
标签: swift uitableview tags custom-cell mpmediaitem