【问题标题】:UIButton doesn't display on UITableViewCell when the product is run产品运行时 UIButton 不显示在 UITableViewCell 上
【发布时间】:2016-08-20 18:07:06
【问题描述】:

我已经在整个互联网上为这个简单的问题寻找了四个小时的答案,但我仍然迷失了方向。我是 Xcode 的初学者,这可能会为我解释所有的困惑。

正如您从图片中看到的,我想在 tableview 中添加一个指向我的应用程序主屏幕的按钮。于是我又多加了一个tableviewcell,将如下代码放入tableviewcontroller中。

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    if (indexPath.row == 0){

        let cell: UITableViewCell = HomeButtonTableViewCell(style: UITableViewCellStyle.Default,
            reuseIdentifier: "LetsGoHome")
        return cell
    }

    else{
        let cell = self.tableView.dequeueReusableCellWithIdentifier("WordListTableCell", forIndexPath: indexPath) as! WordListTableViewCell

        let row = indexPath.row - 1
        cell.formulaLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleHeadline)
        cell.formulaLabel.text = wordListObject.quizList[row]
        cell.formulaImage.image = UIImage(named: formulaImages[row])

        return cell
    }
}

也许我没有告诉你我所做的足够多的事情,但我可以肯定的是(尽管与此问题相关的大多数答案都建议这样做)bringSubviewToFront 无论我以何种方式尝试都不起作用它。

请就我可能在哪些其他方面犯错以及是否有更好的方法让我从 tableview 屏幕导航到我的主屏幕提出建议。我也想提出建议。

【问题讨论】:

  • 在 UITableViewCell 中放置一个 UIButton 不是一个好主意。 UITableViewCell 的目的之一是能够被选中。因此,只需在第一个原型行中插入一个标签,并确保在 func didSelectRowAt:...
  • 感谢您的建议!唯一的问题是......我不知道为什么,但是我在第一个原型单元格中包含的标签和 UIView 根本没有出现,类似于按钮。使用 bringSubviewToFront 或更改 z 位置也无济于事
  • 好的,我明白了。因此,在构建时肯定会出现在行中。请提供您项目的屏幕截图或链接。

标签: ios swift uitableview subview


【解决方案1】:

最好使用导航控制器。

Storyboard example

【讨论】:

    猜你喜欢
    • 2018-05-04
    • 1970-01-01
    • 1970-01-01
    • 2014-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多