TableVIew中的UIImage在选择单元格时移动

时间:2016-09-21 08:58:02

标签: ios swift uitableview uiimageview swift3

我的动态tableView包含UIImage和标签。 我已经完成了一个获取调用以获取一些信息(以填充标签和图像),包含我使用此代码以编程方式设置为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向右,当我按下后退按钮(在详细信息视图中)时,图像是仍在改变位置" (所以,右边10-11 px。)

这是TableViewController代码,位于" viewDidLoad"方法(只从我的数据库中获取数据):

代码段:

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
        }
    }
}

1 个答案:

答案 0 :(得分:0)

解决:问题是Costraints。我刚刚改变了一些费用并且有效!

谢谢@Volodymyr