iOS:UISplitViewController 后退按钮设置查询

标签 ios swift uisplitviewcontroller uibarbuttonitem

多年来,我一直在努力尝试更改 UISplitViewController 中后退按钮的标签。

这是我能想到的唯一解决方案。基本上从 .displayModeButtonItem() 中剥离 Target 和 Action 并将其与我自己的 UIBarButtonItem 一起使用

var backButton = UIBarButtonItem()
if var b = self.splitViewController?.displayModeButtonItem() {
    backButton = UIBarButtonItem(title: "< back", style: .Plain, target: b.target, action: b.action)
}

然后我在我的 Segue 连接中使用这个按钮,如下所示:

if let controller = (segue.destinationViewController as UINavigationController).topViewController as? ManageViewController {
    controller.navigationItem.leftBarButtonItem = backButton
}

它有效,但我对此有 2 个问题:

1) 当我设置标题时,我丢失了“<”符号。如您所见,我已尝试手动添加它,但它看起来不太好。有没有办法在标签旁边加上通常的“<”?

2) 这感觉有点像 hack。我可以这样设置吗?

最佳答案

这是我为回答这个 SO 问题而写的答案... How to name a back button in UISplitViewController .

感谢 Paul Hegarty 和他在斯坦福大学的宝贵讲座,并在 iTunes U 上提供...在这种情况下,他 2013 年的讲座标题为 "Developing iOS 7 Apps for iPhone and iPad"特别是“第 11 课表格 View 和 iPad”。

如果您使用 Storyboard,则:

  • 打开主 Storyboard并选择链接到 Split View Controller 组中的 Master View Controller 的 Navigation Controller;
  • 打开检查器;
  • View Controller 标题下,针对属性 Title,输入您希望在“后退”按钮 V 形旁边显示的字词。

查看使用 Split View Controller 设置的 Master Detail Xcode 模板的屏幕截图...

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

如果您在代码中实例化 View ,则:

  • 获取对主视图 Controller 的导航 Controller 的引用;
  • 使用 NSString 字词设置导航 Controller 的标题属性,您希望这些字词出现在“后退”按钮人字形旁边。

顺便说一句,我强烈建议实现自动布局和尺寸类,您可以删除 后退按钮 属性的文本,并让尺寸类为您的后退按钮确定适当的词。

例如……

remove text in the "Back Button" property

关于iOS:UISplitViewController 后退按钮设置查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26801819/

相关文章:

ios - 如何在 SwiftyJSON 中解析数组和数组数组?

ios - reloadData() 并在没有 Interface Builder 的情况下设置 IBOutlets

objective-c - 在 SplitViewController 中调整 RootViewController 的大小

objective-c - 如何动画切换到 UISplitView?

iphone - 阻止用户以横向方式查看某些 View

ios - Mac Mini 2014 找不到输入设备

ios - 如果不应该,则可选绑定(bind)成功

iOS - DetailViewController 不显示来自 JSON 的多个条目/值

ios - 在 UIWebView 中启用关闭按钮

ios - 错误 : You don’t have permission to save the file in the folder