Skip to content

Instantly share code, notes, and snippets.

@waveacme
Created March 18, 2016 09:19
Show Gist options
  • Save waveacme/ad04bb4d5bd0d9f0df83 to your computer and use it in GitHub Desktop.
Save waveacme/ad04bb4d5bd0d9f0df83 to your computer and use it in GitHub Desktop.
text filed delegate sample
//
// ViewController.swift
// FoodTracker
//
// Created by Jane Appleseed on 5/23/15.
// Copyright ? 2015 Apple Inc. All rights reserved.
// See LICENSE.txt for this sample’s licensing information.
//
import UIKit
class ViewController: UIViewController, UITextFieldDelegate {
// MARK: Properties
@IBOutlet weak var nameTextField: UITextField!
@IBOutlet weak var mealNameLabel: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Handle the text field’s user input through delegate callbacks.
nameTextField.delegate = self
}
// MARK: UITextFieldDelegate
func textFieldShouldReturn(textField: UITextField) -> Bool {
// Hide the keyboard.
textField.resignFirstResponder()
return true
}
func textFieldDidEndEditing(textField: UITextField) {
mealNameLabel.text = textField.text
}
// MARK: Actions
@IBAction func setDefaultLabelText(sender: UIButton) {
mealNameLabel.text = "Default Text"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment