Skip to content

Instantly share code, notes, and snippets.

@jungchris
Created April 15, 2016 14:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jungchris/d2b12e694634dc7a285a2012338dabd4 to your computer and use it in GitHub Desktop.
Save jungchris/d2b12e694634dc7a285a2012338dabd4 to your computer and use it in GitHub Desktop.
Controller to add an item in Swift
//
// AddStuffVC.swift
// HelloToDoSwift
//
// Created by Chris Jungmann on 4/1/16.
// Copyright © 2016 Chris Jungmann. All rights reserved.
//
import UIKit
class AddStuffVC: UIViewController, UITextFieldDelegate {
@IBOutlet weak var textName: UITextField!
@IBOutlet weak var textDescription: UITextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func textFieldShouldReturn(textField: UITextField) -> Bool {
textField.resignFirstResponder()
return true
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
self.view.endEditing(true)
}
@IBAction func buttonAddTouch(sender: UIButton) {
// taskModel.addTask(textName.text!, desc: textDescription.text!)
taskModel.addTask(textName.text!, description: textDescription.text!)
self.view.endEditing(true)
textName.text = ""
textDescription.text = ""
}
/*
// 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.
}
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment