准备在 Swift 中嵌入 tableView 中的 segue [英] Preparing for segue in embedded tableView in Swift

查看:23
本文介绍了准备在 Swift 中嵌入 tableView 中的 segue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 UITableViewController,其中静态单元格通过故事板嵌入到普通的 ViewController 中.这一切都按预期工作.但是,当我想在单击嵌入式 tableview 上的单元格时准备转场时,应用程序崩溃而没有真正的错误.

I have a UITableViewController with static cells embedded in a normal ViewController through a storyboard. This is al working as expected. However when I want to prepare for a segue when a cell on the embedded tableview is clicked the app crashes without a real error.

我有一个用于嵌入式 UITableViewController 的类 TableViewVC 和一个嵌入它的类 RootVC.我想实现这个方法:

I have a class for the embedded UITableViewController, TableViewVC, and a class in which it's embedded, RootVC. I want to implement the method:

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?);

我从 TableViewVC 中的特定静态单元格在我的故事板中创建了 segue.当我在 TableViewVC 中实现这个方法时,它永远不会被调用.它确实在 RootVC 中被调用,但是当我尝试访问 segue.identifier 属性时崩溃.当我在这里调试应用程序时,我可以看到 segue 的类型是:

I created the segue in my storyboard from a specific static cell in my TableViewVC. When I implement this method in TableViewVC it never gets called. It does get called in RootVC however but crashes when I try to access the segue.identifier property. When I debug the app here I can see that the type is of the segue is:

UIStoryboardEmbedSegue

有谁知道我如何正确准备这个 segue 并访问标识符属性以了解点击了哪个单元格?

Does anyone know how I can prepare for this segue properly and access the identifier property to know what cell is clicked?

错误截图:http://cl.ly/image/2z031b2B3i0o>

推荐答案

UIStoryboardEmbedSegue 用于在 ViewController 中嵌入关系.它正在设置您的 RootVC 和 TableVC 之间的父子关系.它崩溃是因为您可能没有为此特定转场设置标识符.如果您对嵌入关系不感兴趣,则不应在 RootVC 中覆盖此函数.

The UIStoryboardEmbedSegue is used for embed relationships in ViewControllers. It is setting up the parent-child relationship between your RootVC and TableVC. It crashes because chances are you didn't se the identifier for this particular segue. You shouldn't be overriding this function in the RootVC if you are not interested in the embed relationship.

看起来您没有正确设置单元格的转场.如果您发布故事板的图片,我们可以查看一下.

It looks like you didn't set up the segue from your cells properly. If you post a image of your storyboard, we can take a look.

另一种方法是通过控制从故事板中 VC 顶部的黄色 VC 图标拖动到您想要的目的地,从您的 TableVC(而不是单元格)设置转场.然后在 didSelectRow.

An alternative to this is to set up a segue from your TableVC (not the cells), by control dragging from the yellow VC icon on top of the VC in the storyboard to the destination you want. And then performing the segue programmatically in didSelectRow.

这篇关于准备在 Swift 中嵌入 tableView 中的 segue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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