Swift 选择行时快速更改UITableViewHeaderFooterView中的文本
当我调用didselectrow时,我试图将标题标签更改为nameLabelText(我单击一行时设置的字符串类型的变量),现在当我选择一行时,调用did集合并打印出我想要的字符串,但它只是不上传标签Swift 选择行时快速更改UITableViewHeaderFooterView中的文本,swift,xcode,Swift,Xcode,当我调用didselectrow时,我试图将标题标签更改为nameLabelText(我单击一行时设置的字符串类型的变量),现在当我选择一行时,调用did集合并打印出我想要的字符串,但它只是不上传标签 var nameLabelText: String? { didSet{ print("did set nameLabelText",nameLabelText as Any) nameLabel.text = nameLabelText r
var nameLabelText: String? {
didSet{
print("did set nameLabelText",nameLabelText as Any)
nameLabel.text = nameLabelText
reloadInputViews()
}
}
lazy var nameLabel: UILabel = {
let label = UILabel()
label.text = "Search Refinements"
label.translatesAutoresizingMaskIntoConstraints = false
label.font = UIFont.boldSystemFont(ofSize: 14)
return label
}()
问题是,当您想要更改标题标签的文本时,您可以通过
让csh=contectionstatusheader()
而不是获取当前的contectionstatusheader
要解决此问题,单击单元格时,获取要更改标签的contectionstatusheader
,并更改其标签的文本。使用didSelectRowAt
方法尝试下面的代码
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.row == 0 {
print("Online Users Only Selected")
let csh = tableView.headerView(forSection: indexPath.section) as! ConntectionStatusHeader;
csh.nameLabelText = "Search Refinements - Online Users Only "
} else {
// Do what you want
}
}
问题是,当您想要更改标题标签的文本时,您可以通过
让csh=contectionstatusheader()
而不是获取当前的contectionstatusheader
要解决此问题,单击单元格时,获取要更改标签的contectionstatusheader
,并更改其标签的文本。使用didSelectRowAt
方法尝试下面的代码
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.row == 0 {
print("Online Users Only Selected")
let csh = tableView.headerView(forSection: indexPath.section) as! ConntectionStatusHeader;
csh.nameLabelText = "Search Refinements - Online Users Only "
} else {
// Do what you want
}
}
您能显示
didSelectRowAt
方法的代码吗?重写func tableView(utableview:UITableView,didSelectRowAt indexath:indexPath){如果indexPath.row==0{print(“仅在线用户选中”),则让csh=contectionstatusheader()csh.nameLabelText=“搜索优化-仅限在线用户”}其他………请更新您的问题。您使用ContectionStatusHeader
做什么?它是一个headerView
或footerView
。您可以写下如何创建它吗?您可以显示didSelectRowAt
方法的代码吗?覆盖函数表视图(uTableView:UITableView,didSelectRowAt indexPath:indexPath){if indexPath.row==0{print(“仅选定在线用户”)让csh=contectionStatusHeader()csh.nameLabelText=“搜索优化-仅限在线用户“}其他………请更新您的问题的didSelectRowAt
。您使用contectionstatusheader
做什么?它是headerView
或footerView
。您能写下您是如何创建它的吗?欢迎@bennypalms661;)欢迎@bennypalms661;)