gpt4 book ai didi

ios - swift : Use of instance member on type 'ViewController' ; did you mean to use a value of type 'ViewController' instead

转载 作者:行者123 更新时间:2023-12-01 19:57:23 25 4
gpt4 key购买 nike

正如标题所示,Swift 告诉我我正在调用 ViewController 类的成员,而不是对象。我查看了许多其他帖子,但无法弄清楚我哪里出错了。

func endEventSteps() {
UserDefaults.standard.set(false, forKey: "hasLoggedIn")
UserDefaults.standard.set(nil, forKey: "usersEmail")
UserDefaults.standard.set(nil, forKey: "usersPassword"
performSegue(withIdentifier: "backToLoginScreen", sender: self)
}
let alertController = UIAlertController(title: "End event", message: "Are you sure you'd like to end this event?", preferredStyle: UIAlertControllerStyle.alert)
let DestructiveAction = UIAlertAction(title: "End",
style: UIAlertActionStyle.destructive,
handler: {(alert: UIAlertAction!) in endEventSteps()})

编辑:我在最后一行收到以下错误:“在类型 'InfoSubmisionViewController' 上使用实例成员 'endEventSteps';您的意思是使用类型为 'InfoSubmisionViewController' 的值吗?”。当我将简单的命令作为处理程序时,代码编译得很好,例如 print("foo")

以上所有代码都在自定义 ViewController 类“InfoSubmissionViewController”中。

最佳答案

假设您有一个名为 DestructiveAction 的 Controller 类, 然后

let DestructiveAction = ...

应该
let destructiveAction = ...

关于ios - swift : Use of instance member on type 'ViewController' ; did you mean to use a value of type 'ViewController' instead,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41722219/

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