【问题标题】:Tags and MPMediaItems in a custom cell自定义单元格中的标签和 MPMediaItems
【发布时间】: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


    【解决方案1】:

    尝试下面的代码。

        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()
         }
    

    【讨论】:

    • 现在你的问题解决了吗?
    猜你喜欢
    • 2015-10-12
    • 1970-01-01
    • 1970-01-01
    • 2013-06-07
    • 2015-05-31
    • 2017-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多