禁止 Storyboard Segue 执行 segue 操作 [英] Inhibit Storyboard Segue from performing segue action

查看:28
本文介绍了禁止 Storyboard Segue 执行 segue 操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题我如何拒绝发生故事板转场?

Question How do I deny a storyboard segue from taking place?

背景:我在第一个可见的视图控制器上有一个静态分组表视图(如果你愿意的话,主菜单).

Context: I have a static grouped table view of options on the first view controller that is visible (the main menu if you will).

我特意提早展示 UI,让用户有机会进行交互并感知快速的负载响应.例如,可能正在导入数据的其他操作发生在后台操作队列中.事实上,我的大部分 UI 功能都已准备就绪,您一看到就可以使用了.

I purposely show the UI early to give the user a chance to interact and perceive a fast load response. Other operations that might be importing data for example, happen on a background operation queue. Most of my UI functions are in fact, ready to go as soon as you see them.

特别是一个菜单项(表格行),在导入一些数据之前还没有准备好(当一切准备就绪时我会发送通知).

One menu item (table row) in particular though, isn't ready until some data is imported (I send a notification when all is ready).

虽然我可以移除这个动作的故事板转场,但它让我思考如何在不满足特定条件的情况下禁止转场触发.

While I could remove the storyboard segue for this action, it got me thinking on how I might inhibit a segue from firing because a certain condition wasn't met.

我可能会在实践中允许 segue,并让目标视图控制器限制初始化,直到它收到它正在等待的通知.

I'll likely allow the segue in practice, and have the destination view controller limit initialization until it receives the notification it is waiting for.

但是可以以编程方式拦截转场并阻止它吗?

But can one intercept a segue and stop it, programmatically?

推荐答案

在 iOS 6.0 及更高版本中,您可以通过覆盖 -[UIViewController shouldPerformSegueWithIdentifier:sender:] 方法并返回 NO.

In iOS 6.0 and later, you can prevent a segue from firing after the action that would normally trigger it has occurred by overriding the -[UIViewController shouldPerformSegueWithIdentifier:sender:] method and returning NO.

这篇关于禁止 Storyboard Segue 执行 segue 操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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