除非选择了单元格,否则UITableViewCell中的按钮不会显示

时间:2015-03-27 20:37:21

标签: ios uitableview swift

我的UITableViewCell中有2个按钮。默认情况下会显示其中一个,另一个仅显示在点击第一个操作后执行操作的时间。由于某种原因,除非选择了单元格,否则按钮不会显示。他们曾经表现出但我显然已经改变了一些东西,我不知道是什么。任何的想法?这是相关的代码:

     override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell: EpisodesCell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! EpisodesCell
    configureCell(cell, indexPath: indexPath)
    return cell
}

func configureCell(cell: EpisodesCell, indexPath: NSIndexPath) {
    let data = fetchedResultsController.objectAtIndexPath(indexPath) as! CDEpisode
    cell.textLabel!.text = data.title
    cell.downloadButton.hidden = false
    cell.downloadButton.tag = indexPath.row
    cell.downloadButton.addTarget(self, action: "downloadButtonClicked:", forControlEvents: UIControlEvents.TouchUpInside)
    if data.isDownloaded == "yes" {
        cell.playButton.hidden = false
    }

}

class EpisodesCell: UITableViewCell {

@IBOutlet weak var playButton: UIButton!
@IBOutlet weak var downloadButton: UIButton!
@IBAction func downloadEpisode(sender: AnyObject) {
    println(sender)
    println(sender.superview)
  }
}

链接到单元格的屏幕截图:https://www.evernote.com/l/ACRiU8RKu9tEr58ULTBzIbk00h688Dt1q-w

谢谢

1 个答案:

答案 0 :(得分:1)

你应该检查一下: https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIView_Class/#//apple_ref/occ/instm/UIView/bringSubviewToFront:

代码应如下所示:

self.view.bringSubviewToFront(button2)