我有一个带有搜索栏的表格视图。当视图最初加载时,我看到在一个空行上显示了一个添加按钮。这应该只在我显示结果时出现。这如何隐藏起来?我试着将隐藏属性设置为true,但没有奏效。Swift - 带按钮的自定义单元格的Tableview
第二部分是我想为按钮附加一个函数,以便按下它时将执行代码以添加行中的朋友。下面是我要支持我的问题截图:
这里是我的自定义单元格的代码:
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
}