如果不满足条件,Xcode Storyboard 会取消推送
我有一个故事板,导航视图控件中有一个按钮,该控件也有文本字段,它使用故事板segue push
。 但是,我进行了一些输入检查,如果任何文本字段为空,我会提醒用户。
我可以这样做,但它会提醒用户,然后切换到另一个视图。
如果按钮 Pressed 方法中不满足 if 条件,是否有办法取消此 push
?
注意:此推送是由故事板界面创建的,而不是由代码创建的。
I have a storyboard with a button in a Navigation View Control, this control has textfields in as well, which uses the storyboard segue push
.
However, I have some input checking, and I alert the user if any of the text fields are empty.
I can do this, BUT it alerts the user, and then switches to the other view.
Is there a way to cancel this push
if an if condition is not met in the button Pressed method?
N.B This push was created by the storyboard interface, not by code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不要通过从按钮拖动到目标控制器来创建 Segue。相反,只需从源控制器拖动到目标控制器即可创建转场。单击 Segue 并使用属性检查器指定 Segue 是推送,并为 Segue 提供标识符 (goToDestination)。然后将该按钮连接到源视图控制器中的 IBAction。在 IBAction 方法中进行检查,如果要进行推送,请添加以下代码行:
Don't create the segue by dragging from the button to the destination controller. Instead, just drag from the source controller to the destination controller to create a segue. Click on the segue and use the attribute inspector to specify the segue is a push and give the segue an identifier (goToDestination). Then connect the button to an IBAction in the source view controller. In the IBAction method do your checking and if you want to do the push add this line of code:
也可以使用以下内容,并将适用于不同类型的 Segue,例如推送、展开等。从 Storyboard 中命名 Segue 并使用此处给出的代码。如果您不希望执行特定的转场,则返回 NO 条件,并默认返回 YES。此方法应该位于源视图控制器中。
The following can also be used and will work for different types of segues like push, unwind, etc. Name the segue from the Storyboard and use the code given here. Return NO for the condition if you do not want the particular segue to be performed and return YES by default. This method should be in the source view controller.
如果buttonAction是必须在按钮单击时执行的方法,则必须调用其中的两个方法
1. 条件检查方法
2. 控制segue的方法
您的验证方法将如下所示,
并且可以通过以下代码段控制segue
If buttonAction is the method that have to execute on button click you have to call two methods inside it
1. Method to check the conditions
2. Method to control the segue
Your validation method will be looking as follows
and segue can be controlled by the following code segment