How to name the return button in a UISplitViewController

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

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

But it does not display the button name. I see only an arrow (arrow works).

I also tried the following in my UITableViewController (News), but that 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 iPad enter image description here

My result on iPhone enter image description here

+7
ios xcode swift ipad uisplitviewcontroller
source share
2 answers

Thanks to Paul Hegarty and his invaluable lectures at Stanford University and available on iTunes U ... in this case, his lectures in 2013 under the heading "iOS 7 Application Development for iPhone and iPad" and, in particular, "Lecture 11 Table View and iPad "

If you are using storyboards, then:

  • Open the main storyboard and select a navigation controller that references the main view controller in your split view controller group;
  • Open inspector;
  • Under the View Controller heading, for the Title property, enter the words that you want to display next to the back button of the chevron.

See a screenshot of the Master Detail Xcode template configured using the Split View controller ...

Interface Create a screenshot with a description of the location of the Title and quot properties for the navigation controller> </a> </p> <p> If you create views in the code: </p> <UL> <li> get a link to the navigation controller for Master View controller; </li> <li> set the title property of this navigation controller with <code> NSString </code> words that you want to display next to the button

As an aside, I would highly recommend the Auto Layout and Size Classes implementation to remove text for the Back Button property and allow size classes to define the appropriate words for your Back button.

For example, according to the question ...

+12
source share

Decision:

Here's how to fix the problem with the back button of the detail view controller:

  • For any view controller that gets on the stack of the main navigation controller, install this title controller. (Either in the viewDidLoad: method, or in the push-view control method prepareForSegue:sender: )
  • Set the title navigation main controller in the child view control method viewDidLoad:

For example, in MasterViewController.m :

 - (void)viewDidLoad { [super viewDidLoad]; [self setTitle:@"Foo"]; } - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[self navigationController] setTitle:[self title]]; } 

This will cause the title of the detail view control button to be synchronized with the title of the top main controller.

What's happening:

UINavigationController , its rootViewController and UINavigationItem have a title property.

Note that the back button displayed for the current view controller is actually the previous backButtonItem view backButtonItem . (See Figure 1-7 Navigation Bar Structure)

A UINavigationController automatically inherits the title value of its root view controller, but will not automatically inherit the title of any other controller that will be pushed onto its stack. This is why, by default, the back button of the detail view controller always displays the title of the root controller of the main navigation controller. You can select, initialize, and click multiple child view controllers, but only one navigation controller is allocated and initialized for each side of the standard controller with a separate view.

In addition, the property view controller navigationItem title (whose value appears on the shortcut in the center of the navigation bar) does not inherit its value from the navigation controller , but from the view controller itself. If you set the view controller property title to โ€œBarโ€ and the title of the navigation controller โ€œFooโ€, โ€œBarโ€ will be displayed on the label displayed in the center of the navigation bar.

+1
source share

All Articles