gpt4 book ai didi

ios - Swift - 带自定义单元格和按钮的表格 View

转载 作者:行者123 更新时间:2023-11-28 16:16:16 25 4
gpt4 key购买 nike

我有一个带有搜索栏的表格 View 。最初加载 View 时,我看到空行上显示了一个添加按钮。这应该只在我显示结果时出现。这怎么能隐藏呢?我尝试将隐藏属性设置为 true 但没有成功。

第二部分是我想将一个函数附加到按钮,以便在按下时执行代码以将 friend 添加到行中。以下是我必须支持我的问题的屏幕截图:

initial view where button should not show

after searching where I want to attach a function to the button

这是我的自定义单元格的代码:

class AddFriendsTableViewCell: UITableViewCell {

@IBOutlet weak var addButton: UIButton!
@IBOutlet weak var nameLabel: UILabel!

@IBOutlet weak var usernameLabel: UILabel!



override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
self.addButton.hidden = true
}

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

// Configure the view for the selected state
}

}

这是我填充单元格的地方:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! AddFriendsTableViewCell

if(self.friendUsername != "" && self.friendName != "")
{
cell.nameLabel.text = self.friendName
cell.usernameLabel.text = self.friendUsername
cell.addButton.hidden = false

}

return cell
}

最佳答案

当您重复使用单元格时,不会调用 awakeFromNib。尝试在您的条件中添加其他部分:

if(self.friendUsername != "" && self.friendName != "") {
cell.nameLabel.text = self.friendName
cell.usernameLabel.text = self.friendUsername
cell.addButton.hidden = false
} else {
cell.addButton.hidden = true
}

关于ios - Swift - 带自定义单元格和按钮的表格 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39043909/

25 4 0
文章推荐: swift - 将 Firebase Auth 用户 UID 写入数据库
文章推荐: javascript - php 风格的函数在 javascript 中检查
文章推荐: javascript - 将 validate ="required:true"添加到您的 html 中
文章推荐: html - 有没有一种简单的方法可以为 HTML
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com