Search code examples
iosobjective-cuitextfieldnslog

Build simple iOS app with text field that prints value using NSLog


I'm trying to learn Objective C and iOS development, but am having trouble. I am trying to create a very basic app that has a text field and that prints out the value entered into the text field using NSLog when the return key is pressed. I have added the text field via storyboard, but am unsure how to create the delegate method needed to make this work. I have thus far added the following code to the ViewController.h file: @property (weak, nonatomic) IBOutlet UITextField *textfld;

Thanks in advance for any help.


Solution

  • Set the delegate of the UITextField outlet to be your ViewController. Then have your ViewController implement the UITextFieldDelegate protocol. Then in the textFieldDidEndEditing: method, print out the text property of the textView input.

    Update

    - (void)viewDidLoad {
        [super viewDidLoad];
        self.txtField.delegate = self;
    }