I have a custom text field class, "loginTextFields". I recently noticed that The view controllers in which I use these text fields are not being deallocated, and I suspect that it has something to do with these text fields... Any guidance is greatly appreciated :) I've looked up quite a few stackoverflow posts but none really helped me out.
The txt field class:
class LoginTextFields: UITextField, UITextFieldDelegate {
override init(frame: CGRect) {
super.init(frame: frame)
delegate = self
setConstraints()
}
}
The view controller:
class LoginController: UIViewController {
@IBOutlet weak var usernameTextField: LoginTextFields!
@IBOutlet weak var passwordTextField: LoginTextFields!
}
I've guessed and added a 'delete' method to the loginTextfield class in an attempt to set everything to nil (was suspecting maybe the delegate had something to do with it not deallocating) when the user segues out of the view controller. I was hoping this would remove any strong reference but it didn't work
func delete() {
self.delegate = nil
self.text = nil
self.leftSideIcon.removeFromSuperview() //small icon inside text field
self.removeFromSuperview()
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…