ScholarQuill logoScholarQuillUniversity Notes
  • Notes
  • Past Papers
  • Blogs
  • Todo
Login
ScholarQuill logoScholarQuillUniversity Notes
Login
NotesPast PapersBlogsTodo
More
SubjectsDiscussionCGPA CalculatorGPA CalculatorStudent PortalCourse Outline
About
About usPrivacy PolicyReportContact
Notes
Past Papers
Blogs
Todo
Analytics
    Current Subject
    🧩
    Mobile Application Development 2
    COMP4126
    Progress0 / 38 topics
    Topics
    1. Creating an iOS App: Understanding Xcode2. Using the Xcode interface builder and objects library3. Understanding view hierarchy and creating a custom app icon4. Outlets, Actions, and Views: Understanding outlets and actions5. Using text fields, buttons, labels, web views, and page controllers6. Using views with subviews and creating views using code7. Using View Controllers: Working with the single view template8. Exploring the app delegate and adding new view controllers9. Transitioning between multiple view controllers using animations10. Application Templates: Tabbar and master detail templates11. The iOS Keyboard: Customizing for different inputs12. Adjusting text field behaviors and dismissing the keyboard13. Detecting keyboard activities with notification center14. Using scroll view and responding to keyboard activities programmatically15. Working with Different iOS Devices (iPhone & iPad): Detecting device hardware16. Dynamically adjusting graphical layouts and creating universal apps17. Using Table Views: Understanding UITableView and UITableViewCell18. Working with UITableView data source and delegate19. Master detail template, drill-down menus, and navigation20. Using property lists for data persistence and creating multi-section tables21. Supporting Screen Rotations: Portrait and landscape modes22. Handling device rotation and forcing specific orientation23. Dynamically adjusting layouts based on rotation24. Working with Databases: Importing sqlite3 and creating a database25. Writing tables, inserting records, and bundling a database with your app26. Checking for database existence and reading/displaying data27. Using Animations & Video: NSTimer class and object transformations28. Rotation, scaling, translation, animating image arrays, and playing video29. Accessing Integrated iOS Apps: Email, Safari, and SMS30. Working with camera and photo library31. Using Web Services: Consuming and parsing XML and JSON32. Integrating Twitter and Facebook with iOS apps33. Working with iOS Maps and Location Services: MapKit and MKMapView34. Getting and displaying user location and directional information35. Displaying map annotations, disclosure buttons, and reverse geocoding36. Working with iCloud37. Working with the Accelerometer: Gyroscope and accelerometer38. Outputting sensor data and using the Shake API
    COMP4126›Adjusting text field behaviors and dismissing the keyboard
    Mobile Application Development 2Topic 12 of 38

    Adjusting text field behaviors and dismissing the keyboard

    3 minread
    472words
    Beginnerlevel

    📱 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 load past papers

    Click on Show Past Papers to see past papers.
    On This Page
      Reading Stats
      Est. reading time3 min
      Word count472
      Code examples0
      DifficultyBeginner