0

Initially, I had a segue connecting a normal UITableview cell to a ViewController, and it worked. My code from before was something like this:

 override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {

        if segue.identifier == "SEGUE" {
            let vc = segue.destinationViewController as! DetailsViewController
            let cell = (sender as! UITableViewCell)
            let title = cell.textLabel!.text
            vc.titleData = title

}
}

Now I created a custom cell and when I run the program, my tableview is populated with the custom cell correctly, only this time the segue doesn't work. I went back in and adjusted it, but I don't know how to get it to work again. Here's my code now:

override func viewDidLoad() {
        super.viewDidLoad()
        //register custom cell
        var nib = UINib(nibName: "tbvcell", bundle: nil)
        self.tableView.registerNib(nib, forCellReuseIdentifier: "cell")
        self.tableView.dataSource = self
        getEarthquakeInfo { (info) in
            self.tableView.reloadData()


            dispatch_async(dispatch_get_main_queue()) {
                self.tableView.reloadData()

            }
        }


    }
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) ->   UITableViewCell {
        var cell: Thecell = self.tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as Thecell
        cell.LocationLabel.text = info[indexPath.row].location
        cell.scaleLabel.text = info[indexPath.row].scale
        cell.TimeLabel.text = info[indexPath.row].time
        return cell

    }

    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject!) {

        if (segue.identifier == "segue") {
        let vc = segue.destinationViewController as DetailsViewController
        if let indexPath = self.tableView.indexPathForSelectedRow(){
        var cell: Thecell = self.tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as Theca
          vc.titleData = info[indexPath.row].location



                }

        }
    }

UPDATE: This is really frustrating me now. My prepareForSegue is never getting called and I don't even know why. I tried didSelectRowAtIndexPath and that's not working either.

my segue My segue identifier Attributes Inspector of tableViewCell

Thecell.swift (my custom cell file)

import UIKit
import Foundation
class Thecell: UITableViewCell {

    @IBOutlet weak var LocationLabel: UILabel!
    @IBOutlet weak var scaleLabel: UILabel!
    @IBOutlet weak var TimeLabel: UILabel!
}

What it looks like when I run it.

If there's anybody out there who can point out what I'm doing wrong, I'd appreciate it.

videoperson
  • 139
  • 1
  • 12
  • 1
    I believe segue.identifier is case sensitive. Your version that worked used "SEGUE" and the version that does not work uses "segue". Did you change the case? – Kevin Horgan Jun 22 '15 at 09:07
  • Somewhere along the way, I think I deleted the segue and added it again, making the identifier "segue" instead of "SEGUE". In my code I remembered to change that, so now in my code it says "segue" and the identifier matches "segue" as well. I'm pretty sure it's not working not because of that. Any other suggestions? – videoperson Jun 22 '15 at 19:28
  • Take a look at this answer to see if it helps. http://stackoverflow.com/questions/26236975/prepareforsegue-not-called-from-custom-uitableviewcell – Kevin Horgan Jun 23 '15 at 08:02

0 Answers0