[英]UIImage in TableVIew moves when cell is selected
I've a dynamic tableView that contains an UIImage
and a label. 我有一个动态的tableView,其中包含一个
UIImage
和一个标签。 I've done a get call in order to get some information (to fill label and images), included links to images that i programmatically set to the UIImage
with this code: 我已经进行了一次get调用,以获取一些信息(以填充标签和图像),包括指向这些图像的链接,这些图像是我通过以下代码以编程方式设置为
UIImage
:
Code Snippet : 代码段:
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
}
}
All is correct, but when i press on a row, in order to see details, the image change position of 10-11 px to the right, and when i press the back button (in the Details view) the image is still in the "changed position" (so, 10-11 px to the right). 一切正确,但是当我按一行以查看详细信息时,图像向右更改10-11像素的位置,而当我按“后退”按钮(在“详细信息”视图中)时,图像仍位于“位置更改”(因此,右侧10-11像素)。
This is the TableViewController code, under "viewDidLoad" method (that only get data from my DB): 这是“ viewDidLoad”方法下的TableViewController代码(仅从我的数据库中获取数据):
Code Snippet: 代码段:
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
}
}
}
Solved: Problems were Costraints. 解决:问题是成本消耗。 I've just changed some costraints and it works!
我刚刚改变了一些成本消耗,并且有效!
Thank you @Volodymyr 谢谢@Volodymyr
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.