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.
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!
}
If there's anybody out there who can point out what I'm doing wrong, I'd appreciate it.