gpt4 book ai didi

ios - 添加后以编程方式删除 UILabel - swift

转载 作者:行者123 更新时间:2023-11-28 06:29:02 26 4
gpt4 key购买 nike

我以编程方式制作了一个 UIView 和两个 UILabel。标签上写着类似这样的内容:“没有帖子,关注某人以添加到您的 Feed 中。”。

self.update.count 显示要显示的帖子数。所以如果它是 0 应该显示我制作的标签。如果不是,则不应显示任何标签。

我已经制作了这段代码,但它不会再次删除标签和 UIView 吗?它在 viewWillAppear 中:

if self.updates.count == 0 {

print("THERE ARE NO POSTS: \(self.updates.count)")
self.tableView.addSubview(self.noPostView)
self.tableView.addSubview(self.noPostLabel)
self.tableView.addSubview(self.noPostText)

//noPostView.anchorToTop(view.topAnchor, left: nil, bottom: view.bottomAnchor, right: nil)
self.noPostView.centerXAnchor.constraintEqualToAnchor(self.tableView.centerXAnchor).active = true
//noPostView.centerYAnchor.constraintEqualToAnchor(tableView.centerYAnchor).active = true
self.noPostView.anchor(self.view.topAnchor, left: nil, bottom: nil, right: nil, topConstant: 80, leftConstant: 0, bottomConstant: 0, rightConstant: 0, widthConstant: self.view.frame.width, heightConstant: self.noPostLabel.frame.height + self.noPostText.frame.height)

self.noPostLabel.anchor(self.view.topAnchor, left: nil, bottom: nil, right: nil, topConstant: 80, leftConstant: 0, bottomConstant: 0, rightConstant: 0, widthConstant: self.noPostView.frame.width, heightConstant: 50)
self.noPostLabel.centerXAnchor.constraintEqualToAnchor(self.noPostView.centerXAnchor).active = true


self.noPostText.anchor(self.noPostLabel.bottomAnchor, left: self.noPostView.leftAnchor, bottom: nil, right: self.noPostView.rightAnchor, topConstant: -20, leftConstant: 35, bottomConstant: 0, rightConstant: 35)
self.noPostText.heightAnchor.constraintEqualToConstant(60).active = true
self.noPostText.centerXAnchor.constraintEqualToAnchor(self.noPostView.centerXAnchor).active = true

self.loadingSpinner.stopAnimating()
} else {
print("THERE ARE: \(self.updates.count) POSTS")

self.tableView.willRemoveSubview(self.noPostView)
self.tableView.willRemoveSubview(self.noPostText)
self.tableView.willRemoveSubview(self.noPostLabel)

}

最佳答案

只需在不需要时隐藏标签,即“self.noPostLabel.isHidden = true”,并在需要时显示它们。

关于ios - 添加后以编程方式删除 UILabel - swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40934659/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com