Reputation: 65
I want to make a text editor and want a reset button, but I don't know I can reset the UITextField
.
Here´s my code:
import Cocoa
class ViewController: NSViewController {
@IBOutlet weak var textField: NSTextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
@IBAction func Quit(_ sender: Any) {
exit(0)
}
@IBAction func Reset(_ sender: Any) {
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
}
Upvotes: 0
Views: 8042
Reputation: 374
just set the text empty the text property:
self.textField.text = ""
or
self.textField.text = nil
That line of code must be in your button action
I also recomend to dont use NS objects. You can import UIKit and use TexField instead of NSTextField, and ViewController instead of NSViewController
Upvotes: 1