如何在UISplitViewController中命名后退按钮 [英] How to name a back button in UISplitViewController

查看:97
本文介绍了如何在UISplitViewController中命名后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 UITableViewController (它的名字是新闻)和 UIViewController (它的名字是DetailViewController)和 UISplitViewController 。我希望它在纵向使用iPad时显示后退按钮。我按下了按钮,但我无法命名。我写了下面的代码

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

但它没有显示按钮的名称。我只看到箭头(箭头有效)。



我也在我的UITableViewController(新闻)中尝试了以下内容但它没有帮助我





我使用此代码为不同的设备使用两个segue。

 覆盖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)
}
}

我在iPad上的结果



我在iPhone上的结果

解决方案

感谢Paul Hegarty及其在斯坦福大学的宝贵讲座,并在iTunes U上提供......在这种情况下,他的2013年讲座名称为



如果您要实例化视图在代码中,然后:




  • 获取对主视图控制器的导航控制器的引用;

  • 设置该导航控制器的title属性,其中 NSString 是您希望在后退按钮V形符号旁边显示的单词。



另外,我强烈建议实施自动布局和大小类,删除后退按钮属性的文本,让大小类确定后退按钮的相应单词。



For例如,根据问题......




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

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

My result on an iPhone

解决方案

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...

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...

这篇关于如何在UISplitViewController中命名后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆