我的 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
谢谢
最佳答案
代码应该是这样的:
self.view.bringSubviewToFront(button2)
关于ios - 除非选择单元格,否则 UITableViewCell 中的按钮不会显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29309784/