正如标题所示,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‘中。
发布于 2017-01-18 22:54:22
假设您有一个名为DestructiveAction的控制器类,那么
let DestructiveAction = ...应该是
let destructiveAction = ...https://stackoverflow.com/questions/41722219
复制相似问题