a developer's notes – a semi-technical web development BLOG

March 20, 2015

Using a Segue with a custom cell in a UITableView

Filed under: IOS-Swift — Duy Nguyen @ 11:57 am
Tags: , , , ,

If you’re using custom cells or programmatically adding in a .xib file cell func prepareForSegue() won’t get called directly. You’ll have to use func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) to call the prepareForSegue method.

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        if segue.identifier == "showDetailSeg" {
            
            if let indexPath = self.tableView.indexPathForSelectedRow() {
                let object = xmlParser.arrParsedData[indexPath.row]
                let controller = (segue.destinationViewController as UINavigationController).topViewController as DetailsViewController
                controller.detailItem = object
                controller.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem()
                controller.navigationItem.leftItemsSupplementBackButton = true
            }
        }
    }
    
    override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        
        self.performSegueWithIdentifier("showDetailSeg", sender: nil)
        
    }

Advertisements

Blog at WordPress.com.