Swift 我一直收到这样一个错误:“我的;隐含使用';自我';关闭;使用';赛尔夫';使捕获语义明确化;
我不断地发现这个错误:Swift 我一直收到这样一个错误:“我的;隐含使用';自我';关闭;使用';赛尔夫';使捕获语义明确化;,swift,Swift,我不断地发现这个错误: Implicit use of 'self' in closure; use 'self.' to make capture semantics explicit 即使我把自我放在代码里。请纠正我 这是我的密码: @IBAction func doneButton(_ sender: Any) { let code = codeTextField.text if code == "TEST" || code == "Test" || code == "t
Implicit use of 'self' in closure; use 'self.' to make capture semantics explicit
即使我把自我放在代码里。请纠正我
这是我的密码:
@IBAction func doneButton(_ sender: Any) {
let code = codeTextField.text
if code == "TEST" || code == "Test" || code == "test" {
var myAlert = UIAlertController(title:"Alert", message: "You are logging into The Test Zoo, right?", preferredStyle: UIAlertController.Style.alert)
let yesAction = UIAlertAction(title: "Yes", style: UIAlertAction.Style.default) {
UIAlertAction in
performSegue(withIdentifier: "welcomeButton", sender:self)
}
还有更多,但yesAction需要更正。
performsgue
是一种方法,您隐式地调用它;显式版本将是self.performsgue(…)
只需将您的代码行从performsgue(带有标识符:“welcomeButton”,发送者:self)
更改为self.performsgue(带有标识符:“welcomeButton”,发送者:self)
“即使我将自我放入代码中”-在哪里?您的代码没有显示所请求的self
。@rmaddy performsgue(标识符为:“welcomeButton”,发件人:self)调用self.performsgue您在viewcontroller上调用performsgue,但在闭包中它不知道在什么上下文中调用该方法,因此需要告诉它要使用哪个viewcontroller实例,这是self。@RPS1222消息与传递给发送方的参数无关。请仔细阅读错误消息,上面写着使用“self”。
,注意点。只有在方法调用performsgue
前面才能添加带有点的self.
。仔细阅读错误消息确实有助于猜测错误所在,即使您并不确切知道。@RPS1222,您能将其标记为正确答案吗?