转到当前视图 UItableView [英] Segue to current view UItableView

查看:22
本文介绍了转到当前视图 UItableView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 tableview 中有一个未定义的级别数(深度),所以我希望能够在视图和它本身之间创建一个 segue,这样只要我有子级别要发现,我就可以调用它.我该怎么做?

I have an undefined number of levels (depth) in my tableview, so i'd like to be able to create a segue between the view and itself so that i can call it as long as i have sub levels to discover. How can i do that ?

我想过在需要时直接使用 [self.navigationView pushViewController],但我希望新控制器在我的 SB 中使用定义的视图.

I've thought of directly using [self.navigationView pushViewController] when i need it, but i'd like the new controller to use the defined view in my SB.

谢谢,

目前我找到的唯一解决方案是复制 VC,在 VC1 和 VC2 之间设置一个名为showNext"的 segue,并在 VC1 和 VC2 之间设置一个 segue 以相同的方式调用.没有更好的解决方案吗?

For now the only solution i've found is duplicating the VC, setting a segue between VC1 and VC2 called 'showNext', and a segue between VC1 and VC2 called the same way. Isn't there a better solution ?

推荐答案

如果您正在使用动态单元格原型,您显然可以毫无问题地从表格视图单元格到控制器进行 segue.

If you're using dynamic cell prototypes, you obviously can do a segue from the table view cell to the controller without any problem.

当您进行转场时,您会得到:

When you make your segue, you end up with:

但是让我们想象一下,有一些原因对您不起作用,例如您不能从单元格中获得 segue(例如,您需要从 didSelectRowAtIndexPath 调用 segue,而不是在选择单元格时).在这种情况下,您不能使用以前的技术.

But let's imagine for a second that there's some reason that doesn't work for you, e.g. you could not have a segue from the cell (for example, you need to invoke segue from didSelectRowAtIndexPath, not upon selecting the cell). In this case, you couldn't use that previous technique.

在这种情况下有几个选项:

There are a couple of options in this case:

  1. 正如 Chris 指出的,如果只支持 iOS 6 及更高版本,请使用上述技术,但(a) 确保您的 didSelectRowAtIndexPath 使用 self 作为 sender 然后让 shouldPerformSegueWithIdentifier 只允许 segue,如果sender == self (这样当sender是table view cell时,它会被取消);

  1. As pointed out by Chris, if only supporting iOS 6 and above, use the above technique, but (a) make sure your didSelectRowAtIndexPath uses self for the sender and then have shouldPerformSegueWithIdentifier only allow the segue if the sender == self (thus when the sender is the table view cell, it will be canceled);

也许更简单,只是根本不定义 segue 并手动使用 didSelectRowAtIndexPath instantiateViewControllerWithIdentifier 然后push/根据需要呈现该视图控制器;或

Perhaps even easier, just don't define a segue at all and have your didSelectRowAtIndexPath manually instantiateViewControllerWithIdentifier and then push/present that view controller as appropriate; or

您可以使用以下笨拙的解决方法:简而言之,向您的视图控制器添加一个按钮(将其向下拖动到底部的栏),它不会显示在视图中,但你可以使用它的 segue.首先,将圆形按钮拖到场景底部的控制器栏:

You can use the following, kludgy work-around: In short, add a button to your view controller (drag it down to the bar at the bottom), where it won't show up on the view, but you can use its segues. So first, drag the rounded button to the controller's bar at the bottom of the scene:

现在你可以从那个按钮到你的视图控制器:

Now you can make a segue from that button to your view controller:

因此,您最终又会遇到自我引用的转场:

And thus, you end up with the self-referential segue again:

您必须为该 segue 提供一个标识符,以便您可以通过 performSegueWithIdentifier 以编程方式调用它,但它可以工作.不是最优雅的解决方案,但我认为这比在故事板上多一个场景要好.

You must give that segue an identifier, so you can invoke it programmatically via performSegueWithIdentifier, but it works. Not the most elegant of solutions, but I think it's better than having an extra scene on your storyboard.

这些都不理想,但您有很多选择.

None of these are ideal, but you have lots of options.

这篇关于转到当前视图 UItableView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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