title: Swift Custom Back Button and Destination
body: <p>I am currently using SWRevealViewController for a sidebar menu in my app. When I click one of the options, the destination view controller doesn't have a 'back' button because it hasn't come from a proper view controller (i.e. page to go back to). </p>
  
  <p>Therefore I am wanting to manually create a back button on the destination view controller which will go back to the home view controller. </p>
  
  <p>I have looked at the code here: <a href="https://stackoverflow.com/questions/22076066/how-do-i-manually-set-the-back-destination-in-ios-apps">How do I manually set the &quot;Back&quot; destination in iOS apps</a></p>
  
  <p>But I am struggling to implement this in Swift (one error after another!). Any help? Thanks!</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I have tried the suggestion below, but the back button just doesn't appear. This may have something to with the fact I have the navbar hidden in other views and do the following on the destination view:</p>
  
  <pre><code>override func viewDidLoad() {
      super.viewDidLoad()
      navigationController.setNavigationBarHidden(false, animated:true)
      var myBackButton:UIButton = UIButton.buttonWithType(UIButtonType.Custom) as UIButton
      myBackButton.addTarget(self, action: "popToRoot:", forControlEvents: UIControlEvents.TouchUpInside)
  
      var myCustomBackButtonItem:UIBarButtonItem = UIBarButtonItem(customView: myBackButton)
      self.navigationItem.leftBarButtonItem = myCustomBackButtonItem
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
  }
  
  func popToRoot(sender:UIBarButtonItem){
      self.navigationController.popToRootViewControllerAnimated(true)
  }
  </code></pre>
  
  <p>Not sure why the back button won't show up?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>This is the prepareForSegue from my sidebar view controller. If there is a way to check for the segue identifier 'test' then I can set the back button from here?</p>
  
  <pre><code>- (void) prepareForSegue: (UIStoryboardSegue *) segue sender: (id) sender
  {
  // Set the title of navigation bar by using the menu items
  NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
  UINavigationController *destViewController = (UINavigationController*)segue.destinationViewController;
  destViewController.title = [[_menuItems objectAtIndex:indexPath.row] capitalizedString];
  
  
  if ( [segue isKindOfClass: [SWRevealViewControllerSegue class]] ) {
      SWRevealViewControllerSegue *swSegue = (SWRevealViewControllerSegue*) segue;
  
      swSegue.performBlock = ^(SWRevealViewControllerSegue* rvc_segue, UIViewController* svc, UIViewController* dvc) {
  
          UINavigationController* navController = (UINavigationController*)self.revealViewController.frontViewController;
          [navController setViewControllers: @[dvc] animated: NO ];
          [self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
      };
  
  }
  
  }
  </code></pre>