PiterPan
PiterPan

Reputation: 1802

Missing back button in my ViewController after seque from TableViewControler in Swift

In my project, I have a few View Controllers and I use UINavigationController.

When I make a seque from UIViewController to UITableViewController I have "back" button added automatically, but when I make seque from UITableViewController to UIContentViewController tapped a cell, I don't have a "back" button in UIContentViewController.

Plan of my app is here plan of aplication and kind of segue

The segue in UITableViewController looks like that:

 override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    let CV =   self.storyboard?.instantiateViewControllerWithIdentifier("ContentViewController") as! ContentViewController

    let tnumber = tableView.indexPathForSelectedRow?.item

    CV.titleContent = daneOWpisach?[tnumber!]["title"]
    CV.webContent = daneOWpisach?[tnumber!]["description"]
    CV.category = category

self.presentViewController(CV, animated: true, completion: nil)
}

What should I do, if I would like to have a back button in UIContentViewController added automatically?

Upvotes: 2

Views: 1327

Answers (1)

Koti Tummala
Koti Tummala

Reputation: 756

In your code you are presenting the view controller on cell selection..! Back button will show only if you perform push not on presenting the view.

In the above diagram what I have seen is you already make the segue from UITableViewController to UIContentViewController. select the segue and go to attribute inspector give the identifier for the segue.

On the cell selection perform the segue action with the identifier you specified

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

self.performSegueWithIdentifier("Your Segue name", sender: sender)
}

If you want to pass data to destination view controller, do it like below..

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
        if segue.identifier == "Your Segue name" {
          let CV =   segue.destinationViewController as! ContentViewController
           let tnumber = tableView.indexPathForSelectedRow?.item

        CV.titleContent = daneOWpisach?[tnumber!]["title"]
        CV.webContent = daneOWpisach?[tnumber!]["description"]
        CV.category = category 
        }
    }

Hope this helps you

Upvotes: 3

Related Questions