Created
March 16, 2017 15:17
-
-
Save loldi/e932089c1cb5c07ef55e5321b508102a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
class ViewController: UIViewController, UITextFieldDelegate { | |
@IBOutlet weak var txtInput: UITextField! | |
@IBOutlet weak var txtOutput: UITextView! | |
var items:[String] = [] | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
self.txtInput.delegate = self | |
} | |
@IBAction func addItem(_ sender: Any) { | |
if(txtInput.text! == ""){ | |
return | |
} | |
items.append(txtInput.text!) | |
txtOutput.text = "" | |
for item in items { | |
txtOutput.text.append("\(item)\n") | |
} | |
txtInput.text = "" | |
txtInput.resignFirstResponder() | |
} | |
func textFieldShouldReturn(_ textField: UITextField) -> Bool { | |
if(txtInput.text! == ""){ | |
self.view.endEditing(false) | |
return true | |
} | |
items.append(txtInput.text!) | |
txtOutput.text = "" | |
for item in items { | |
txtOutput.text.append("\(item)\n") | |
} | |
txtInput.text = "" | |
txtInput.resignFirstResponder() | |
self.view.endEditing(true) | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment