简体   繁体   English

如何在Xcode Interface Builder中向表视图控制器(带有静态单元格)添加导航项?

[英]How do I add a navigation item to a Table View Controller (with static cells) in Xcode Interface Builder?

I'm building my first iOS app using Xcode 9.3 and Swift 4.1. 我正在使用Xcode 9.3和Swift 4.1构建我的第一个iOS应用。

My app is basically a View Controller which contains a Table View and is embedded in a Navigation Controller. 我的应用程序基本上是一个包含表视图的View Controller,并嵌入在Navigation Controller中。 When I tap a cell in the Table View the app transitions to a subordinate View Controller. 当我在“表格视图”中点击一个单元格时,应用程序将转换为从属视图控制器。 Because I'm using a Naviagtion Controller the subordinate view already has a navigation bar at the top with a helpful button back to its parent. 因为我使用的是Naviagtion控制器,所以下级视图已经在顶部具有导航栏,并带有一个返回其父级的有用按钮。

I also want to reveal a Settings screen when the user taps a “Settings” button in the navigation bar. 我也想在用户点击导航栏中的“设置”按钮时显示“设置”屏幕。 Using a new View Controller as a placeholder for the Settings screen works – I can reveal the Settings screen with a Modal segue and the screen can have a button or navigation item to unwind the segue back to my initial view. 将新的View Controller用作“设置”屏幕的占位符-我可以使用“模态”按钮显示“设置”屏幕,并且屏幕上可以具有按钮或导航项以将按钮恢复为我的初始视图。

Everything works and it's all good. 一切正常,一切都很好。

However I want to build my Settings screen using a Table View with static cells. 但是我想使用带有静态单元格的表格视图来构建“设置”屏幕。 I just need a couple of cell groups with various controls where the user can set their preferences. 我只需要几个带有各种控件的单元格组,用户可以在其中设置其首选项。 For Xcode to support static cells I have to use a Table View Controller as the basis for my Settings screen. 为了使Xcode支持静态单元格,我必须使用Table View Controller作为“设置”屏幕的基础。 This is where the problems arise. 这就是问题所在。

With a Table View Controller I can no longer place a button or navigation item on the screen to trigger the unwind segue. 使用Table View Controller,我无法再在屏幕上放置按钮或导航项来触发展开选择。

I could make the segue a “Show” so it becomes part of the navigation hierarchy imposed by the Navigation Controller. 我可以将segue设置为“ Show”,使其成为导航控制器强加的导航层次结构的一部分。 This does provide a navigation bar on my Settings screen with a navigation item that transitions back to the original View Controller. 这确实在我的“设置”屏幕上提供了一个导航栏,其中包含一个导航项,该导航项可以转换回原始的View Controller。

But this isn't what I want. 但这不是我想要的。 From a UX point of view the Settings page is now a subordinate page in the hierarchy. 从UX的角度来看,“设置”页面现在是层次结构中的下级页面。 What I really want is for the Settings page to be revealed modally with a horizontal flip so it feels like a separate screen in the app. 我真正想要的是通过水平翻转以模态方式显示“设置”页面,因此感觉就像应用程序中的单独屏幕一样。

So my question is, how can I add the necessary UI widgets to a Table View Controller so that I can trigger the unwind segue? 所以我的问题是,如何将必要的UI小部件添加到Table View Controller中,以便可以触发展开序列? Or am I overlooking something more fundamental in my application's architecture? 还是我忽略了应用程序体系结构中更基本的东西? To me this seems like a fairly obvious approach to including a settings screen but after hours of searching I can't find instances of anyone else having this problem. 对我来说,这似乎是包括设置屏幕的相当明显的方法,但是经过数小时的搜索,我找不到其他人遇到此问题的实例。 Nor can I find any tutorials or examples of how to implement an in-app settings screen. 我也找不到如何实施应用内设置屏幕的任何教程或示例。

I am not sure whether I understood your problem correctly. 我不确定我是否正确理解您的问题。 I think you want to add some buttons to UITableViewController. 我认为您想向UITableViewController添加一些按钮。 For this here is my solution. 为此,这是我的解决方案。 Embedding UITableViewController in UINavigationController will work for you. 将UITableViewController嵌入UINavigationController中将为您工作。 When tapped on Settings button present navigation controller modally. 轻按“设置”按钮时,导航控制器将以模态显示。 As navigation controller have table view controller as root view controller, tableviewcontroller will have navigation bar. 由于导航控制器将表视图控制器作为根视图控制器,因此tableviewcontroller将具有导航栏。 You can add your buttons to it. 您可以添加按钮。

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

相关问题 iOS开发-如何显示使用自定义Table View Controller在Interface Builder中创建的静态单元格? - iOS development - How to display static cells created in Interface Builder with custom Table View Controller? 如何使用Interface Builder添加导航控制器? - How to add a Navigation Controller with Interface Builder? 如何在Interface Builder中向UITableViewController添加导航栏? - How do I add a Navigation Bar to a UITableViewController in Interface Builder? 如何使用xcode接口构建器向UIButton添加填充? - How do I add padding to a UIButton using the xcode interface builder? Xcode界面构建器:未设置静态表视图单元格字体 - Xcode interface builder: Static table view cell font is not being set Interface Builder IB - 导航控制器,跳过视图 - Interface Builder IB - Navigation Controller, skipping a view 带有静态单元格的表视图控制器 - Table view controller with static cells 如何在“今日视图”中添加UIVisiualEffectView而不在Xcode / Interface Builder中模糊? - How to add a UIVisiualEffectView in Today View without blur in Xcode / Interface Builder? 如何在表视图下添加视图,但它会滚动显示单元格? - How do I add a view underneath a Table View, but it scrolls with the cells? 静态单元格在Interface Builder中显示为空(运行XCode 7.1) - Static Cells are showing empty in Interface Builder (running XCode 7.1)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM