简体   繁体   中英

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

As the title suggests, Swift is telling me I'm calling a member on the ViewController class, not an object. I've looked at numerous other posts and cannot figure out where I'm going wrong.

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()})

EDIT: I get the following error on the last line: "Use of instance member 'endEventSteps' on type 'InfoSubmisionViewController'; did you mean to use a value of type 'InfoSubmisionViewController' instead?". code compiles fine when I put simple command as the handler, such as print("foo")

All of the above code is within a custom ViewController class, 'InfoSubmissionViewController'.

Assuming that you have a controller class named DestructiveAction , then

let DestructiveAction = ...

should be

let destructiveAction = ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM