iOS:让segue等待登录成功 [英] iOS: Make segue wait for login success
问题描述
我正在使用XCode 4.2的故事板功能设计iOS应用。该应用程序有一个登录屏幕,其中包含用户名和密码,并有一个登录按钮。按下登录按钮会触发另一个视图控制器的推送序列。但是,我希望seque等到登录成功后再继续下一个视图控制器。
I am designing an iOS app using XCode 4.2's storyboard feature. The app has a login screen that takes a username and password and has a button to log in. Pushing the login button triggers a push seque to another view controller. However, I want the seque to wait until the login comes back successful before proceeding to the next view controller.
我知道 prepareForSegue:sender:
但是我的问题是:登录调用是异步的。因此,我无法在那里进行登录。
I know about prepareForSegue:sender:
but heres my issue: the login call is asynchronous. I therefore cannot perform the login there.
有什么可以解决这个问题吗?我可以在故事板中创建一个仅在我想要的时候触发的seque(而不是单击按钮时)?
Is there someway around this? Can I create a seque in the storyboard that is only triggered when I want it to be (as opposed to when a button is clicked)?
推荐答案
好的,我已经弄明白了。我已经将 UIButton
中的segue定义为下一个 UIViewController
。按照这种方式定义,没有办法有条件地执行segue。
Ok, I have figured it out. I had defined a segue from a UIButton
to the next UIViewController
. As defined in this manner, there is no way to conditionally execute the segue.
我没有把segue放在按钮上,而是从第一个<$ c c中做了一个segue $ c> UIViewController 到另一个 UIViewController
。这定义了segue,但不与它相关联。从那里我可以简单地调用 performSegueWithIdentifier:sender:
当我想要执行segue时(在我的情况下是异步任务完成时)。
Instead of putting the segue on the button, I made a segue from the first UIViewController
to the other UIViewController
. This defines the segue, but associates no action with it. From there I can simply call performSegueWithIdentifier:sender:
when I want that segue to execute (in my case being when the async task is complete).
这对我来说的主要优势在于IB维持其结构。
The main advantage of this for me is that IB maintains its structure.
非常感谢@cli_hlt指出我正确的方向( +1)。
Big thanks to @cli_hlt for pointing me in the right direction (+1).
这篇关于iOS:让segue等待登录成功的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!