简体   繁体   English

Swift:将分段控制器添加到导航栏中,并保留标题和导航按钮

[英]Swift: Add segmented controller to a navigation bar, and keep the title + nav buttons

I'd like to add a segmented controller to a navigation bar, below the title. 我想在标题下方的导航栏中添加分段控制器。

At the moment, I've got a storyboard UITableViewController with a CoreData-sourced dynamic table, embedded in a UINavigationController. 目前,我有一个故事板UITableViewController,其中包含一个基于CoreData的动态表,并嵌入在UINavigationController中。 I'd like the UISegmentedController to differentiate the sorting of the table. 我想要UISegmentedController区分表的排序。

There seems to be obj-C solutions available stackoverflow.com/questions/29480433/ and stackoverflow.com/questions/18813563 , but I'm looking for a Swift solution, that resembles the native apps. 似乎有可用的obj-C解决方案stackoverflow.com/questions/29480433/stackoverflow.com/questions/18813563 ,但我正在寻找一种类似于本机应用程序的Swift解决方案。 I've also tried putting the segmented controller into a table cell with little success (can't get the action recognised). 我还尝试将分段控制器放入表单元中,但收效甚微(无法识别动作)。 I'd prefer not to abandon the table view controller. 我不想放弃表视图控制器。

Any suggestions? 有什么建议么?

I replaced the UITableViewController with a UIViewController and UITableView, then added the UISegmentedController to a UIToolBar positioned below the UINavigationBar. 我用UIViewController和UITableView替换了UITableViewController,然后将UISegmentedController添加到位于UINavigationBar下方的UIToolBar中。

I used removeShadow for the navbar, then clipsToBounds for the toolbar. 我将removeShadow用于导航栏,然后将clipsToBounds用于工具栏。 I also added another View to simulate the bottom shadow on the toolbar (because I couldn't get the toolbar shadow/background position function to work). 我还添加了另一个视图来模拟工具栏上的底部阴影(因为我无法使工具栏阴影/背景位置功能正常工作)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将分段控件添加到导航栏并使用按钮保留标题 - Add segmented control to navigation bar and keep title with buttons Swift 5 自定义导航栏封面标题和按钮 - Swift 5 custom navigation bar cover title and buttons iOS 8 Swift导航栏标题,按钮在基于选项卡的应用程序中不显示 - iOS 8 Swift navigation bar title, buttons not showing in tab based application 从Storyboard在UITableViewController上添加带标题的导航栏而没有导航控制器 - Add Navigation Bar with title without Navigation controller on UITableViewController from Storyboard 使用 Tab Bar Controller Swift 在导航栏中添加新的栏按钮 - Add new bar button in Navigation Bar with a Tab Bar Controller Swift Swift 2:更改与标签栏控制器相关的视图上的导航标题 - Swift 2 : Change navigation title on a view related to a Tab Bar Controller 如何将分段控件添加到导航栏? (iOS) - How to add a segmented control to a navigation bar ? (iOS) 如何在iPhone应用程序开发的导航栏上的分段控制器上添加下一个和上一个按钮? - How can i add a next and previous button at the segmented Controller on a navigation bar in iphone application development? Swift / XCode 6.4:向导航栏中的导航控制器添加后退按钮 - Swift/XCode 6.4: add back button to navigation controller in navigation bar swift:导航栏中的标题字体 - swift: Font of title in navigation bar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM