Xcode April 27, 2016 Wednesday

Source: Internet
Author: User

Connect the UI to Code

Theme

    • The Weak keyword means that it's possible for this property to has no value (is nil) at some point in its life.

-@IBOutlet weak var Nametextfield:!

    • An implicitly unwrapped optional, which are a optional type that would always has a value after the value is first set.

Target-action is a design in which one object sends a message to another object when a specific event occurs.

Create Outlets for UI Elements

To connect the text field to the Viewcontroller.swift code

A delegate is an object, which acts on behalf of, or in coordination with, another object.

Any object can serve as a delegate for another object as long as it conforms to the appropriate protocol.

Because Viewcontroller keeps a reference to the text field and you'll make Viewcontroller the text field ' s delegate.

Class viewcontroller:a href= "" uiviewcontroller/a, a href= "" uitextfielddelegate/a {



By adopting the protocol, you gave the Viewcontroller class the ability to identify itself as a uitextfielddelegate. This means your can set it as the delegate of the text field and implement some of its behavior to handle the text field ' s User input.

To set Viewcontroller as the delegate for Nametextfield

Handle the text field ' s user input through delegate callbacks.

Nametextfield.delegate = Self

The Uitextfielddelegate protocol contains optional methods, which means that you ' re not required to implement them.

When the user taps a text field, it automatically becomes first responder. In a app, the first responder is a object that's first on the line for receiving many kinds of app events, including Ke Y events, motion events, and action messages, among others. In other words, many of the events generated by the user is initially routed to the first responder.

As a result of the text field becoming first responder, IOS displays the keyboard and begins an editing session for that T Ext field. What a user types using this keyboard gets inserted into the text field.

When a user wants to finish editing the text field, the text field needs to resign its first-responder status. Because the text field would no longer is the active object in the app, events need to get routed to a more appropriate obj Ect.

This is the where your implementation of uitextfielddelegate methods comes in. You need to specify, the text field should resign its first-responder status, the user taps a button to end Editin G in the Text field. The Textfieldshouldreturn (_:) method, which gets called when the user taps Return (or in this case, done) o n the keyboard.

To implement the Uitextfielddelegate protocol method Textfieldshouldreturn (_:)  

Xcode April 27, 2016 Wednesday

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.