Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to name a back button in UISplitViewController

I have UITableViewController (its name is News) and UIViewController (its name is DetailViewController) and UISplitViewController. I want it to show a back button when I use an iPad in portrait orientation. I made the button but I cannot name it. I wrote following code

detailController.navigationItem.leftBarButtonItem = self.splitViewController?.displayModeButtonItem()
                detailController.navigationItem.leftItemsSupplementBackButton = true
                detailController.navigationItem.leftBarButtonItem?.title = navigationController?.topViewController.title

But it doesn't show the name of the button. I see only the arrow (the arrow works).

I also tried the following in my UITableViewController(News) but it didn't help me

enter image description here

I use two segues for different devices with this code.

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath){
        var screen = UIScreen.mainScreen().currentMode?.size.height
        if (UIDevice.currentDevice().userInterfaceIdiom == UIUserInterfaceIdiom.Pad) || screen >= 2000 && UIDevice.currentDevice().orientation.isLandscape == true  && (UIDevice.currentDevice().userInterfaceIdiom == .Phone){
            performSegueWithIdentifier("showDetailParse", sender: nil)
            self.dismissViewControllerAnimated(true, completion: nil)
        } else if (UIDevice.currentDevice().userInterfaceIdiom == .Phone) {
            performSegueWithIdentifier("showParse", sender: nil)
        }
    }

My result on an iPad enter image description here

My result on an iPhone enter image description here

like image 911
Alexander Khitev Avatar asked Jul 09 '15 13:07

Alexander Khitev


Video Answer


1 Answers

Thanks to Paul Hegarty and his invaluable lectures at Stanford University and available on iTunes U... in this case his 2013 lectures under the title "Developing iOS 7 Apps for iPhone and iPad" and specifically "Lecture 11 Table View and the iPad".

If you're using storyboards, then:

  • Open your main storyboard and select the Navigation Controller that links to the Master View Controller in your Split View Controller group;
  • Open the Inspector;
  • Under the heading View Controller, against the property Title, enter the words that you would like to appear alongside the "Back" button chevron.

See screenshot of Master Detail Xcode template set up with a Split View Controller...

Interface Building screenshot detailing location of "Title" property for Navigation Controller

If you're instantiating views in code, then:

  • obtain a reference to the Navigation Controller for the Master View controller;
  • set the title property of that Navigation Controller with the NSString of words that you would like to appear alongside the "Back" button chevron.

As an aside, I would highly recommend implementation of Auto Layout and Size Classes, that you remove the text for the Back Button property and let size classes determine the appropriate words for your Back Button.

For example, as per the question...

remove text in the "Back Button" property

like image 106
andrewbuilder Avatar answered Sep 30 '22 14:09

andrewbuilder