开发者社区> 问答> 正文

如何在UITableViewCell单元格中隐藏大小的按钮?

我有UITableView和UITableViewCell。我从API获得数据。有些物品有链接,有些则没有。如果该项目没有链接,我将用一个图书图标隐藏按钮。当我使用这个方法时(请看下面)按钮是隐藏的,但是当表视图用一本书重用这个单元格图标时就不会回来了。我怎么能修好它?

var addButtonTrailingConstraint =  openPdfButton.widthAnchor.constraint(equalToConstant: 0)
    if link == nil{
        NSLayoutConstraint.activate([addButtonTrailingConstraint])


    }else{
         NSLayoutConstraint.deactivate([addButtonTrailingConstraint])
    }

}

https://i.stack.imgur.com/Qt31h.jpg

展开
收起
游客5akardh5cojhg 2019-12-25 16:23:26 4461 0
1 条回答
写回答
取消 提交回答
  • 你需要

    if link == nil { openPdfButton.widthAnchor.constraint(equalToConstant: 0).isActive = true } else { openPdfButton.constraints.forEach { openPdfButton.removeConstraint($0) } }

    2019-12-25 16:23:41
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载