的背景下,當用戶點擊登錄按鈕,應用程序將檢查與網絡服務的憑據,如果用戶被授權的用戶名和密碼存儲在userDefaults(用於自動登錄申請再次)註銷按鈕動作不靈
現在我用我的下一個頁面(用戶去登錄成功後)上退出按鈕,這是我這不工作是註銷按鈕的代碼。
據我,在註銷的水龍頭,它應該刪除userDefaults,並返回到登錄頁面。 目前我不關心的樣子,只是幫助我的代碼。
功能,用於將按鈕。
override func viewDidLoad()
{
super.viewDidLoad()
let doneItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.trash, target: nil, action: #selector(self.logoutButtonTapped(_:)));
navigationItem.rightBarButtonItem = doneItem;
// Do any additional setup after loading the view.
}
功能用於註銷按鈕:
func logoutButtonTapped(_ sender: Any)
{
let defaults = UserDefaults.standard
defaults.removeObject(forKey: "userName")
defaults.removeObject(forKey: "userPassword")
let newViewObject = storyboard?.instantiateViewController(withIdentifier: "LoginPageViewController") as! LoginPageViewController //LoginPageViewController is my login view file, and identifier also has the same name.
navigationController?.pushViewController(newViewObject, animated: true)
}
你能證明你的stroyboard場景 –
了'target'設置爲'self' –