简体   繁体   English

您可以在情节提要中为自己定义Segue吗?

[英]Can you define a Segue in the storyboard to self?

I have an app that represents a folder structure. 我有一个代表文件夹结构的应用程序。 I have a UITableViewController for the folders and files listing, and a UIViewController for the Documents. 我有一个用于文件夹和文件列表的UITableViewController,以及一个用于文档的UIViewController。

I want to be able to recursively navigate through the folder structure, so I want to reuse the Folder UITableView multiple times while I let the user drill down a folder structure. 我希望能够递归地浏览文件夹结构,因此我想多次重用Folder UITableView,同时让用户深入研究文件夹结构。

Is there a way to draw a segue from the UITableViewController to self so when I select a folder I present another instance of the view, but with the content of the subfolder? 有没有一种方法可以将UITableViewController中的对象绘制到self上,所以当我选择一个文件夹时,我将显示另一个视图实例,但带有子文件夹的内容?

I did this in previous versions of Xcode, but I cannot figure this out on Xcode 9. 我在以前版本的Xcode中做到了这一点,但是我无法在Xcode 9上解决这个问题。

Yes you can do it. 是的,你可以做到。 Add a hidden button in view controller and drag & drop segue self view controller. 在视图控制器中添加隐藏按钮,然后拖放segue自视图控制器。

I've never created a segue link to the same view controller, but based on Halil's answer above, it sounds like it's possible. 我从未创建到同一个视图控制器的segue链接,但是基于上述Halil的回答,这听起来似乎是可行的。

Rather than messing with hidden buttons, though, why don't you give your scene a storyboard identifier, and then instantiate and push/present your view controller through code? 但是,为什么不给场景一个情节提要标识符,然后通过代码实例化并推送/呈现视图控制器,而不是让隐藏的按钮弄乱呢? You could put your logic in the table view's tableView(_:didSelectRowAt:) method. 您可以将逻辑放在表视图的tableView(_:didSelectRowAt:)方法中。

您可以在Interface Builder 屏幕截图中使用ViewController的Storyboard Reference和Storyboard ID。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM