Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/116.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2008/2.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
Ios 如何更改我在tableView中设置的图像(u:willDisplayHeaderView:forSection:)?_Ios_Swift_Header_Tableview - Fatal编程技术网

Ios 如何更改我在tableView中设置的图像(u:willDisplayHeaderView:forSection:)?

Ios 如何更改我在tableView中设置的图像(u:willDisplayHeaderView:forSection:)?,ios,swift,header,tableview,Ios,Swift,Header,Tableview,我在tableView中为每个tableView的标题部分设置了一个图像(uu3;:willDisplayHeaderView:forSection:),如下所示: let image = UIImage(named: "arrow-down") let imageView = UIImageView(image: image!) imageView.frame = CGRect(x: 220, y: 12, width: 10, height: 5) view.

我在tableView中为每个tableView的标题部分设置了一个图像(uu3;:willDisplayHeaderView:forSection:),如下所示:

    let image = UIImage(named: "arrow-down")
    let imageView = UIImageView(image: image!)
    imageView.frame = CGRect(x: 220, y: 12, width: 10, height: 5)
    view.addSubview(imageView)
    header.addSubview(imageView)
为了尝试更改图像(我使用一个V形符号来显示折叠部分的可能性),我尝试了这种方式,但它仅设置顶部标题,相反,我想替换特定部分中的图像(我已获得部分项Int):

如何更改特定部分显示的图像

我读了这个问题,但在这一部分我没有一个按钮

我还发现了其他类似的问题,但我对Objective-C不太了解,在当前的Swift中无法轻松转换代码而不会出错

If you know the specific position, you can do it at the moment when the table is loading the elements if what you want is to add an initial image (Option 1), if what you want is that when you touch the cell change the image you can do it the following way (Option 2)

-----------
Option 1
-----------
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
     if(indexPath.row == //index of your cell){ 
      let frame = CGRect(x: 220, y: 12, width: 10, height: 5)
      let headerImageView = UIImageView(frame: frame)
      let image: UIImage = UIImage(named: "arrow-up")!
      headerImageView.image = image
     }
}

-----------
Option 2
-----------

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
     if(indexPath.row == //index of your cell){ 
      let frame = CGRect(x: 220, y: 12, width: 10, height: 5)
      let headerImageView = UIImageView(frame: frame)
      let image: UIImage = UIImage(named: "arrow-up")!
      headerImageView.image = image
     }
}
If you know the specific position, you can do it at the moment when the table is loading the elements if what you want is to add an initial image (Option 1), if what you want is that when you touch the cell change the image you can do it the following way (Option 2)

-----------
Option 1
-----------
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
     if(indexPath.row == //index of your cell){ 
      let frame = CGRect(x: 220, y: 12, width: 10, height: 5)
      let headerImageView = UIImageView(frame: frame)
      let image: UIImage = UIImage(named: "arrow-up")!
      headerImageView.image = image
     }
}

-----------
Option 2
-----------

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
     if(indexPath.row == //index of your cell){ 
      let frame = CGRect(x: 220, y: 12, width: 10, height: 5)
      let headerImageView = UIImageView(frame: frame)
      let image: UIImage = UIImage(named: "arrow-up")!
      headerImageView.image = image
     }
}