I cannot transfer an image and text from a tableView to another imageView using prepareForSegue method.
foodimages is an array holding imageNames of type string.
I have also tried:
let imgName = "image\(index).png"
but failed.
import UIKit
class TableView: UITableViewController,UITableViewDataSource,UITableViewDelegate {
var foodNames: [String] = ["Food1","Food2","Food3","Food4","Food5","Food6","Food7","Food8"];
var foodImages: [String] = ["image1", "image2","image3","image4","image5","image6","image7","image8"];
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("tblFoto", forIndexPath: indexPath) as! UITableViewCell
cell.textLabel!.text = foodNames[indexPath.row]
var image : UIImage = UIImage(named: foodImages[indexPath.row])!
cell.imageView!.image = image
return cell
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
tableView.deselectRowAtIndexPath(indexPath, animated: true)
self.performSegueWithIdentifier("showIMG", sender: indexPath)
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "showIMG") {
var destViewController: imgView = segue.destinationViewController as! imgView
var index = self.tableView.indexPathForSelectedRow()!.row
let imgName = foodImages[index] //"image\(index).png"
let data = UIImage(named: imgName)!
destViewController.photo = data
}
}
Second Class named "imgView" is
import UIKit
class imgView: UIViewController {
@IBOutlet var secView: UIImageView!
var photo: UIImage!
override func viewDidLoad() {
secView.image = photo
}
}
In debug area it gives:
index (Int)7
imgName (String) "KLWR"
data (UIImage) 0x000000010d667e10 0x000000010d667e10
photoan UIImage as well? how do you detect that the image is in fact not transfered? - luk2302deselectRowAtIndexPath,self.tableView.indexPathForSelectedRow()is still returning a value. - Vasil Garov