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

1 Comment »

  1. Reblogged this on SutoCom Solutions.

    Comment by SutoCom — March 21, 2015 @ 7:01 am | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: