gpt4 book ai didi

ios - 在单元格中加载时隐藏/显示@IBOUlet @IBAction

转载 作者:行者123 更新时间:2023-11-30 10:59:19 24 4
gpt4 key购买 nike

我试图仅在某些值可用时让按钮显示。

@IBAction func instagramButtonHide(_ sender: Any) {
if(self.thisLens.instagramURL.isEmpty){
addInstagramButton.isHidden = true
}else{
let url = URL(string: thisLens.instagramURL)!
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
}

该代码有效,但前提是您单击它。所以我想让我们将它放在 viewDidAppear 中,以便它在 View 加载时加载,但由于它位于单元格中,所以我不能这样做。

因此,如果 instagramURL 的值为空,我不希望显示该按钮。

我觉得有一个简单的解决办法,但我找不到它。

@IBOutlet weak var addFacebookButton: UIButton!
@IBOutlet weak var shareButton: UIButton!

var thisLens: WordPressPost!


override func awakeFromNib() {
super.awakeFromNib()
// Initialization code


addFacebookButton.isHidden = self.thisLens.facebookURL.isEmpty
}

override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

// Configure the view for the selected state
}

@IBAction func favoriteButtonPressed(_ sender: UIButton) {

}

@IBAction func facebookButtonClicked(_ sender: Any) {
let url = URL(string: thisLens.facebookURL)!
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}

还有另一个

    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

var thisLens: WordPressPost!

var numberOfPosts = posts.count
if searchController.isActive {
numberOfPosts = filteredPosts.count
}
if indexPath.row != numberOfPosts {
var thisPost: WordPressPost
if searchController.isActive {
thisPost = filteredPosts[indexPath.row]
}
else {
thisPost = posts[indexPath.row]
}
let cell = tableView.dequeueReusableCell(withIdentifier: "lensCell", for: indexPath) as! LensCell

cell.thisLens = thisPost
if thisPost.authorName == "" {
cell.authorNameLabel.text = "No Author"
}
else {
cell.authorNameLabel.text = thisPost.authorName
}
if thisPost.title == "" {
cell.lensNameLabel.text = "No Title"
}
else {
cell.lensNameLabel.text = thisPost.title
}

if thisPost.image != nil {
cell.snapCodeImageView.image = thisPost.image
cell.imageLoadingIndicator.stopAnimating()
}
else {
cell.snapCodeImageView.image = nil
cell.imageLoadingIndicator.startAnimating()
downloadImage(url: URL(string: thisPost.imageURL)!, cellIndexPath: indexPath, wasSearchControllerActive: searchController.isActive, typingUID: currentTypingUID)
}
return cell
}
else {
let cell = tableView.dequeueReusableCell(withIdentifier: "loadingCell", for: indexPath) as! LoadingCell
cell.loadingIndicator.startAnimating()
return cell
}
}

最佳答案

然后在单元格的 awakeFromNib 内执行此操作

addInstagramButton.isHidden = self.thisLens.instagramURL == nil

或在cellForRowAt

let item = ///
cell.addInstagramButton.isHidden = item.instagramURL == nil

关于ios - 在单元格中加载时隐藏/显示@IBOUlet @IBAction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53585229/

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