0
我有一個動態tableView,它包含一個UIImage
和一個標籤。 我爲了得到一些信息做一個GET調用(填寫標籤和圖像),包括鏈接到我編程設置爲UIImage
與此代碼的圖像:當選擇單元格時,TableVIew中的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像素的權利,當我按下後退按鈕(在詳細信息視圖)圖像是仍然處於「變化的位置」(所以,在右邊10-11像素)。
這是TableViewController代碼,在 「viewDidLoad中」 的方法(即只從我的DB數據):
代碼段:
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
}
}
}
膏didSelectMethod – Volodymyr
@Volodymyr你的代碼我並沒有實現這個 「覆蓋FUNC的tableView(_的tableView:UITableView的!didSelectRowAt indexPath:IndexPath)」 我的觀點方法,因爲我有它的問題(如果實現,當我選擇單元格時,它執行2個segue,我不知道爲什麼)。 –
比粘貼方式,處理您的水龍頭 – Volodymyr