Created
March 18, 2016 09:19
-
-
Save waveacme/ad04bb4d5bd0d9f0df83 to your computer and use it in GitHub Desktop.
text filed delegate sample
This file contains hidden or 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
// | |
// 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