ScholarQuill logoScholarQuillUniversity Notes
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
Study Tools
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
Contact
ScholarQuill logo
My Semester
Explore Notes
Past Papers12 New
Video CoursesNew
Search
Settings
GPA/CGPA Calculator
Schedule & To-Do
Student Portal
Contact
ScholarQuill logoScholarQuillUniversity Notes
Study PortalCOMP4126Textfield Behaviors Di…
Ctrl + K
Login
Explore
Search
Semester
Papers
CGPA
    COMP4126

    Mobile Application Development 2

    Progress0 / 38 done
    Topics38
    1Understanding Xcode2Using the Xcode interface builder and objects library3Understanding view hierarchy and creating a custom app icon
    4Understanding outlets and actions5Using text fields, buttons, labels, web views, and page controllers6Using views with subviews and creating views using code
    7Working with the single view template8Exploring the app delegate and adding new view controllers9Transitioning between multiple view controllers using animations
    10Tabbar and master detail templates
    11Customizing for different inputs12Adjusting text field behaviors and dismissing the keyboard13Detecting keyboard activities with notification center14Using scroll view and responding to keyboard activities programmatically
    15Detecting device hardware16Dynamically adjusting graphical layouts and creating universal apps
    17Understanding UITableView and UITableViewCell18Working with UITableView data source and delegate19Master detail template, drill-down menus, and navigation20Using property lists for data persistence and creating multi-section tables
    21Portrait and landscape modes22Handling device rotation and forcing specific orientation23Dynamically adjusting layouts based on rotation
    24Importing sqlite3 and creating a database25Writing tables, inserting records, and bundling a database with your app26Checking for database existence and reading/displaying data
    27NSTimer class and object transformations28Rotation, scaling, translation, animating image arrays, and playing video
    29Email, Safari, and SMS30Working with camera and photo library
    31Consuming and parsing XML and JSON32Integrating Twitter and Facebook with iOS apps
    33MapKit and MKMapView34Getting and displaying user location and directional information35Displaying map annotations, disclosure buttons, and reverse geocoding36Working with iCloud
    37Gyroscope and accelerometer38Outputting sensor data and using the Shake API
    3 min read
    Topic 12 of 38
    Topic Study Note Illustration
    12

    Adjusting text field behaviors and dismissing the keyboard

    Text field behavior refers to how a UITextField responds to user actions such as typing, autocorrection, capitalization, and keyboard appearance.

    πŸ“± Adjusting Text Field Behaviors & Dismissing the Keyboard (iOS – Xcode)


    βœ… 1. Definition

    πŸ”Ή Text Field Behavior

    Text field behavior refers to how a UITextField responds to user actions such as typing, autocorrection, capitalization, and keyboard appearance.

    πŸ”Ή Dismissing the Keyboard

    It means hiding the on-screen keyboard when the user is done entering text.


    🧠 2. Key Concepts

    πŸ”Ή First Responder

    • The active text field that currently shows the keyboard
    • Only one view can be first responder at a time

    πŸ”Ή Resigning First Responder

    • The process of closing the keyboard
    • Done using:
    textField.resignFirstResponder()
    

    βš™οΈ 3. Adjusting Text Field Behaviors


    πŸ”Ή 1. Keyboard Type

    textField.keyboardType = .emailAddress
    

    πŸ”Ή 2. Secure Text Entry (Password Fields)

    passwordField.isSecureTextEntry = true
    

    πŸ”Ή 3. Auto-Capitalization

    textField.autocapitalizationType = .words
    

    Options:

    • none
    • words
    • sentences
    • allCharacters

    πŸ”Ή 4. Auto-Correction

    textField.autocorrectionType = .no
    

    πŸ”Ή 5. Return Key Type

    textField.returnKeyType = .done
    

    ⌨️ 4. Dismissing the Keyboard


    πŸ”Ή Method 1: Tap Return Key (Delegate Method)

    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true
    }
    

    πŸ‘‰ When user presses β€œDone”, keyboard hides.


    πŸ”Ή Method 2: Tap Outside Screen

    Step 1: Add Tap Gesture

    let tapGesture = UITapGestureRecognizer(target: self, action: #selector(dismissKeyboard))
    view.addGestureRecognizer(tapGesture)
    

    Step 2: Dismiss Keyboard Function

    @objc func dismissKeyboard() {
        view.endEditing(true)
    }
    

    πŸ”Ή Method 3: Manually Resign First Responder

    textField.resignFirstResponder()
    

    πŸ“Š 5. Diagram Description (for Exams)

    Draw:

    TextField (Active) β†’ Keyboard Visible
            ↓
    Tap Return / Tap Screen
            ↓
    Keyboard Dismissed
    

    πŸ’‘ 6. Example App

    🎯 Login Screen

    • Username field

    • Password field

    • Keyboard hides on:

      • Done button
      • Screen tap
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true
    }
    
    @objc func hideKeyboard() {
        view.endEditing(true)
    }
    

    πŸ“Œ 7. Important Rules / Tips

    • Always dismiss keyboard to improve UX
    • Use return key behavior for better flow
    • Add tap gesture for modern apps
    • Avoid leaving keyboard open unnecessarily
    • Use delegate methods for better control

    ⚠️ 8. Common Mistakes

    • ❌ Keyboard not dismissing due to missing delegate
    • ❌ Forgetting endEditing(true)
    • ❌ Not enabling user interaction on view
    • ❌ Poor keyboard navigation between fields

    🧠 9. Best Practices

    • Move to next field using Return key
    • Dismiss keyboard after form submission
    • Use gestures for intuitive UX
    • Keep input flow smooth and logical

    πŸ“ 10. Likely Exam Questions

    1. What is meant by text field behavior?
    2. How do you dismiss the keyboard in iOS?
    3. Explain first responder in iOS.
    4. Write code to hide keyboard using return key.
    5. What is resignFirstResponder()?
    6. How do you dismiss keyboard by tapping outside?
    7. Explain auto-capitalization and auto-correction.
    8. Why is keyboard dismissal important in apps?

    πŸ“š 11. Quick Revision Summary

    • Text field behavior controls input settings

    • Keyboard can be customized using:

      • Keyboard type
      • Return key
      • Auto-capitalization
    • Keyboard dismissal methods:

      • Return key β†’ resignFirstResponder()
      • Tap outside β†’ endEditing(true)
      • Manual dismissal
    • Improves user experience and app usability


    ← Previous topic 11
    The iOS Keyboard: Customizing for different inputs
    Next topic 13 β†’
    Detecting keyboard activities with notification center

    Past Papers

    Open this section to view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    3mremaining
    472words
    Beginnerlevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Mobile Application Development 2