Gabriel Rodrigues
Gabriel Rodrigues

Reputation: 510

How use Back Button in Navigation Item

When a have an ViewController and insert Navigation Item create automatically a Back button. In my tableView i use an didSelectRowAtIndexPath to case into the ViewS and this views are using the same navigation Item, but dont create the back button.

Upvotes: 1

Views: 332

Answers (3)

Guilherme Caraciolo
Guilherme Caraciolo

Reputation: 132

You can also do a push in your previous view controller in the method tableView:didSelectedRowAtIndexPath:

 func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {

  var newViewController = ..
  self.navigationController!.pushViewController(newViewController, animated: true)
 }

And it is done. The back button is already there.

Upvotes: 1

Karlos
Karlos

Reputation: 1661

You can try unwind segue. Check the following link.

Tutorial

Upvotes: 0

keji
keji

Reputation: 5990

The back buttons are created automatically on a push/segue. If you want to create this functionality yourself you would have to set the leftBarButtonItem property of the UINavigationItem and implement a method to call:

func backBTPressed() {
     self.navigationController.popViewControllerAnimated(yes)
}

See:

Add a back arrow to leftBarButtonItem?

creating back arrow shaped leftBarButtonItem on UINavigationController

Upvotes: 1

Related Questions