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

标签 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

谢谢

最佳答案

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

代码应该是这样的:

self.view.bringSubviewToFront(button2) 

关于ios - 除非选择单元格,否则 UITableViewCell 中的按钮不会显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29309784/

相关文章:

iOS:以编程方式在 UIView 中绘制线条

ios - 如何在 Swift 3 中访问这些数组的第二部分?

ios - 如何在堆栈 View 中水平居中 UISwitch?

javascript - iOS Safari 顶部和底部栏问题

IOS/Swift JSON 请求后渲染表

ios - 线程 1 : signal SIGABRT when getting Reusable cell for TableView

ios - 从 CMMotionManager 获取 SCNCamera 的正确值

ios - UIImage animationImages 色调颜色?

ios - MFMailComposeViewController 不会关闭

ios - UITableView 设置