gpt4 book ai didi

ios - 在我快速按下按钮后,在 segue 之前执行一些代码

转载 作者:搜寻专家 更新时间:2023-10-31 08:18:04 26 4
gpt4 key购买 nike

我有一个转到另一个 View 的按钮。我想在 segue 移动之前执行一些代码。我面临的问题是 segue 在代码有机会完成之前转到另一页。因此,在 View 更改之前,用户默认值中的值不会更改。我的问题是如何让代码运行并在它完成后让 segue 触发?这是我目前所拥有的:

 @IBAction func onLogoutClick(sender: AnyObject) {
//clear all url chache
NSURLCache.sharedURLCache().removeAllCachedResponses()
//null out everything for logout
email = ""
password = ""
self.loginInformation.setObject(self.email, forKey: "email")
self.loginInformation.setObject(self.password, forKey: "password")
self.loginInformation.synchronize()
//self.view = LoginView
}

最佳答案

你有几个选择;

首先是从 IB 中的按钮中删除操作,然后在 UIViewController 对象和您的下一个场景之间创建一个转场;

@IBAction func onLogoutClick(sender: AnyObject) {
//clear all url chache
NSURLCache.sharedURLCache().removeAllCachedResponses()
//null out everything for logout
email = ""
password = ""
self.loginInformation.setObject(self.email, forKey: "email")
self.loginInformation.setObject(self.password, forKey: "password")
self.loginInformation.synchronize()

self.performSegueWithIdentifier("logoutSegue",sender: self)
}

或者你可以摆脱@IBAction方法并实现prepareForSegueWithIdentifier

override func prepareForSegue(segue: UIStoryboardSegue!, sender: AnyObject!) {
if segue.identifier == "logoutSegue" {
//clear all url chache
NSURLCache.sharedURLCache().removeAllCachedResponses()
//null out everything for logout
email = ""
password = ""
self.loginInformation.setObject(self.email, forKey: "email")
self.loginInformation.setObject(self.password, forKey: "password")
self.loginInformation.synchronize()
}
}

关于ios - 在我快速按下按钮后,在 segue 之前执行一些代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37473471/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com