gpt4 book ai didi

ios - 当选择单元格时,TableVIew 中的 UIImage 会移动

转载 作者:行者123 更新时间:2023-11-30 13:03:55 26 4
gpt4 key购买 nike

我有一个动态 tableView,其中包含 UIImage 和标签。我已经完成了 get 调用,以便获取一些信息(以填充标签和图像),其中包括我使用以下代码以编程方式设置到 UIImage 的图像的链接:

代码片段:

if let url = NSURL(string: chiesa.foto) { //chiesa.foto is taken from GET req
if let data = NSData(contentsOf: url as URL) {
chiesa.image = UIImage(data: data as Data)! //chiesa.image is an UIImage
}
}

一切都是正确的,但是当我按一行时,为了查看详细信息,图像会向右更改 10-11 px 的位置,当我按后退按钮(在“详细信息” View 中)时,图像会变为仍然处于“更改的位置”(因此,向右 10-11 像素)。

这是“viewDidLoad”方法下的 TableViewController 代码(仅从我的数据库获取数据):

代码片段:

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

// MARK: - Table view data source

override func numberOfSections(in tableView: UITableView) -> Int {
// #warning Incomplete implementation, return the number of sections
return 1
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// #warning Incomplete implementation, return the number of rows
return chiese.count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ChieseTableViewCell", for: indexPath) as! ChieseTableViewCell

let chiesa = chiese[indexPath.row]
cell.labelNome.text = chiesa.nome
if(cell.photoImageView == nil){
print("nil")
}else{
cell.photoImageView.image = chiesa.image
}
cell.backgroundColor = UIColor.clear
return cell
}

override func prepare(for segue: UIStoryboardSegue, sender: Any?){
if segue.identifier == "selectedChiesa" {
var nextScene = segue.destination as! ChiesaSelezionataViewController

// Pass the selected object to the new view controller.
if let indexPath = self.tableView.indexPathForSelectedRow {
let nomeChiesa = chiese[indexPath.row].nome
let storiaChiesa = chiese[indexPath.row].storia
nextScene.nome = nomeChiesa
nextScene.storia = storiaChiesa
}
}
}

最佳答案

已解决:问题是约束。我刚刚更改了一些约束并且它起作用了!

谢谢@Volodymyr

关于ios - 当选择单元格时,TableVIew 中的 UIImage 会移动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39611897/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com