Change Text for NavigationController back button with TableView Delegate

237 views Asked by At

I'm trying to change the text that follows the < on the Navigation Controller. I successfully accomplished this in a UIViewController with a TableView that is its own DataSource and Delegate with code like this:

 func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    var newVC = NewViewController()
    self.title = "HomeVC"
    navigationController?.showViewController(newVC, sender: indexPath)
}

When "HomeViewController" is presented, the back button on the Navigation Controller shows "< HomeVC" - the ViewController that we just came from.

Now, I'm trying to accomplish this with another UIViewController that has a TableView, but the DataSource and Delegate are in a separate file. Following the same logic as above, this is what I tried:

 class CalendarTableDataSource: NSObject, UITableViewDataSource, UITableViewDelegate {
     ...
     func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        var newVC = NewViewController()
        self.navController?.title = "HomeVC"  // ----> did not work
        HomeViewController().title = "HomeVC"    // ----> did not work
        self.navController?.showViewController(newVC, sender: indexPath)
    }
}

Ideas, anyone? Assuming that I want to keep the DataSource and Delegate in a separate file.

0

There are 0 answers