gpt4 book ai didi

swift - 自定义单元格中的标签和 MPMediaItems

转载 作者:行者123 更新时间:2023-11-28 12:49:40 28 4
gpt4 key购买 nike

我有一个使用自定义单元格的 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()
}

最佳答案

尝试下面的代码。

    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.button = indexPath.row
return cell
}

@IBAction func handleSelection(sender: AnyObject) {
println(sender.tag)
let songToHandle = tableData.items![sender.tag!]
queryAsCollectionItems?.append()
}

关于swift - 自定义单元格中的标签和 MPMediaItems,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36857629/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com