Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 选择行时快速更改UITableViewHeaderFooterView中的文本_Swift_Xcode - Fatal编程技术网

Swift 选择行时快速更改UITableViewHeaderFooterView中的文本

Swift 选择行时快速更改UITableViewHeaderFooterView中的文本,swift,xcode,Swift,Xcode,当我调用didselectrow时,我试图将标题标签更改为nameLabelText(我单击一行时设置的字符串类型的变量),现在当我选择一行时,调用did集合并打印出我想要的字符串,但它只是不上传标签 var nameLabelText: String? { didSet{ print("did set nameLabelText",nameLabelText as Any) nameLabel.text = nameLabelText r

当我调用didselectrow时,我试图将标题标签更改为nameLabelText(我单击一行时设置的字符串类型的变量),现在当我选择一行时,调用did集合并打印出我想要的字符串,但它只是不上传标签

 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;)