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 PortalCOMP4126App Delegate Adding Vi…
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 8 of 38
    Topic Study Note Illustration
    08

    Exploring the app delegate and adding new view controllers

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

    📱 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 view and download past papers

    Click on Show Past Papers to load available exam papers.

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

    No headings found

    Study Toolkit

    Subject Portal

    Mobile Application Development 2