繁体   English   中英

使用未解决的标识符“ self”

[英]Use of unresolved identifier 'self'

我正在使用Swift开发Mac OS X应用程序。

这是我的第一次,我认为它将与iOS上的相同。

所以我在代码上得到了这个错误(在标题中):

import Cocoa
import AppKit

        class LoginViewController: NSViewController {


            @IBOutlet weak var emailTextField: NSTextField!
            @IBOutlet weak var passwordTextField: NSSecureTextField!
            override func viewDidLoad() {
                super.viewDidLoad()

                // Do any additional setup after loading the view.
            }

            override func viewDidAppear() {

            }

                super.viewDidAppear()

                if NSUserDefaults.standardUserDefaults().valueForKey("uid") != nil && CURRENT_USER!.authData != nil
                {
                    self.logoutButton.hidden = false
                }

            }
            func didReceiveMemoryWarning() {
                super.didReceiveMemoryWarning()
                // Dispose of any resources that can be recreated.
            }


            /*
            // MARK: - Navigation

            // In a storyboard-based application, you will often want to do a little preparation before navigation
            override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
                // Get the new view controller using segue.destinationViewController.
                // Pass the selected object to the new view controller.
            }
            */


            func loginAction(sender: AnyObject)
            {
                let email = self.emailTextField.text
                let password = self.passwordTextField.text
                ...
            }
    }

我必须写些什么而不是写些什么?

使用self是正确的。 尝试使用属性stringValue代替text

这是对我有用的代码:

@IBOutlet weak var emailTextField: NSTextField!

@IBAction func sendTapped(sender: AnyObject) {
  let email = self.emailTextField.stringValue
  print(email)
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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