1L3*_*L30 9 uiviewcontroller ios segue swift
我想在我的应用程序中执行"连接"按钮.当您点击它时,如果您有正确的登录信息,它将打开一个新页面.
但是,我读到我们无法撤消segue,我想我需要手动调用它.你有好主意吗 ?
我还是尝试过这样的事:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject) {
if checkLog == true
{
//finish
}
else
{
// undo
}
}
@IBAction func ConexTAP(sender: UIButton)
{
//check login
}
Run Code Online (Sandbox Code Playgroud)
mxb*_*mxb 14
您可以在以下方法中执行凭据检查ViewController:
func shouldPerformSegueWithIdentifier(_ identifier: String!,
sender: AnyObject!) -> Bool
Run Code Online (Sandbox Code Playgroud)
或者,您可以将UIButton视图绑定到视图控制器中的操作,在此处执行检查,然后按代码触发segue.
小智 7
在Swift中,您可以执行以下操作:
步骤1:将序列从ViewControllerA插入到ViewControllerB。选择应该从ViewControllerA本身开始,而不是从任何控件(如Button)开始。
步骤2:在情节提要中为segue赋予唯一标识符。例如:seageFromAtoB
步骤3:在您的ViewControllerforA.swift中编写:
if(condition == true) {
self.performSegueWithIdentifier("seageFromAtoB", sender: self)
}
Run Code Online (Sandbox Code Playgroud)
如果您正在其他某个线程中执行某些任务,则使用performSegueWithIdentifier可能会引发异常。
如果出现此错误,则应使用:
if(condition==true){
NSOperationQueue.mainQueue().addOperationWithBlock {
self.performSegueWithIdentifier("seageFromAtoB", sender: self)
}
}
Run Code Online (Sandbox Code Playgroud)
这将在特定条件下执行从ViewControllerA到ViewControllerB的选择。
| 归档时间: |
|
| 查看次数: |
10341 次 |
| 最近记录: |