2016-04-26 8 views
0

私は、MPMediaItemsとボタン(他のものの中でも)で設定されたカスタムセルを使ってUITableViewを持っています。 didSelectRowAtIndexPathではなく、特定のセルのMPMediaItemでどのボタンがタップされているかに関して、私はアクションを実行しようとしています。私はいろいろなアプローチを試してきましたが、タグは可能性が高いと信じていますが、正しい実装を得ることはできません。私は、コレクションの最初のアイテムまたは最後のアイテムを取得するようにみえるだけです。 MPMediaItemsを扱うときにタグを設定する正しい方法は何ですか?一部のコードは以下のとおりです。カスタムセル内のタグと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() 
    } 

答えて

2

コードを鳴らしてみてください。

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

ここで問題は解決しましたか? –

+0

これはうまくいきました...ありがとう! – rocketman240

関連する問題