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›Exploring the app delegate and adding new view controllers
    Mobile Application Development 2Topic 8 of 38

    Exploring the app delegate and adding new view controllers

    3 minread
    579words
    Beginnerlevel

    📱 Exploring the App Delegate & Adding New View Controllers (iOS – Xcode)


    🧩 PART 1: Exploring the App Delegate


    ✅ 1. Definition

    The App Delegate is a central class in an iOS app that handles the app’s lifecycle events such as launching, backgrounding, and termination.

    👉 File name: AppDelegate.swift


    🧠 2. Key Concepts

    🔹 App Lifecycle

    The sequence of states an app goes through:

    • Launch
    • Active
    • Background
    • Terminated

    🔹 Role of App Delegate

    • App startup configuration
    • Handling system-level events
    • Managing app state transitions

    ⚙️ 3. Important Methods in App Delegate

    func application(
        _ application: UIApplication,
        didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
    ) -> Bool {
        // App setup code
        return true
    }
    

    📌 Common Methods

    Method Purpose
    didFinishLaunchingWithOptions Called when app launches
    applicationDidEnterBackground App goes to background
    applicationWillEnterForeground App returns to foreground
    applicationWillTerminate App is about to close

    📊 Diagram Description (for Exams)

    Draw lifecycle flow:

    Launch → Active → Background → Foreground → Terminated
    

    📌 Important Rules

    • App Delegate runs before UI appears
    • Used for global app settings
    • Avoid placing UI logic here

    💡 Example

    func applicationDidEnterBackground(_ application: UIApplication) {
        print("App in Background")
    }
    

    🧭 PART 2: Adding New View Controllers


    ✅ 1. Definition

    A View Controller manages a single screen. Adding new view controllers allows you to create multiple screens in your app.


    🧠 2. Key Concepts

    🔹 Multiple Screens

    • Each screen = one view controller
    • Navigation between screens is required

    🔹 Types of Navigation

    • Push (Navigation Controller)
    • Present (Modal)

    ⚙️ 3. Steps to Add a New View Controller


    🔹 Step 1: Open Storyboard

    • Open Main.storyboard

    🔹 Step 2: Add View Controller

    • Drag View Controller from Objects Library

    🔹 Step 3: Design UI

    • Add labels, buttons, etc.

    🔹 Step 4: Create Swift File

    • File → New → Cocoa Touch Class
    • Name it (e.g., SecondViewController)

    🔹 Step 5: Link Class to View Controller

    • Select new screen → Identity Inspector
    • Set class name

    🔹 Step 6: Add Navigation


    🔸 Option 1: Segue (Storyboard)

    • Control + Drag from button → new view controller

    • Select:

      • Show (Push)
      • Present Modally

    🔸 Option 2: Programmatically

    let vc = storyboard?.instantiateViewController(withIdentifier: "SecondVC") as! SecondViewController
    self.present(vc, animated: true)
    

    🔹 Step 7: Set Storyboard ID

    • In Identity Inspector → set identifier (e.g., "SecondVC")

    🔁 4. Passing Data Between View Controllers

    vc.data = "Hello from First Screen"
    

    📊 Diagram Description (for Exams)

    Draw:

    ViewController1 → (Button Click) → ViewController2
    

    📌 5. Important Rules / Tips

    • Always assign Storyboard ID
    • Use Navigation Controller for push navigation
    • Keep each ViewController focused on one task
    • Avoid strong coupling between controllers

    💡 6. Example

    🎯 Two-Screen App

    Screen 1:

    • Button → "Next"

    Screen 2:

    • Label → "Welcome"

    👉 On button click → navigate to screen 2


    ⚠️ 7. Common Mistakes

    • ❌ Not setting Storyboard ID
    • ❌ Not linking class properly
    • ❌ Wrong segue type
    • ❌ Force unwrapping causing crash

    📝 8. Likely Exam Questions

    1. Define App Delegate.
    2. Explain the role of App Delegate in iOS.
    3. Describe app lifecycle states.
    4. What is didFinishLaunchingWithOptions?
    5. How do you add a new view controller in Xcode?
    6. Explain different navigation methods.
    7. Write code to navigate to another screen.
    8. How is data passed between view controllers?

    📚 9. Quick Revision Summary

    🔹 App Delegate

    • Manages app lifecycle
    • Handles system-level events
    • Key method: didFinishLaunchingWithOptions

    🔹 View Controllers

    • Each screen = one controller

    • Add via storyboard

    • Navigate using:

      • Segue
      • Code

    👉 Multi-screen apps require multiple view controllers


    Previous topic 7
    Using View Controllers: Working with the single view template
    Next topic 9
    Transitioning between multiple view controllers using animations

    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 count579
      Code examples0
      DifficultyBeginner