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›Using Table Views: Understanding UITableView and UITableViewCell
    Mobile Application Development 2Topic 17 of 38

    Using Table Views: Understanding UITableView and UITableViewCell

    4 minread
    624words
    Beginnerlevel

    📱 Using Table Views: Understanding UITableView and UITableViewCell (iOS – Xcode)


    ✅ 1. Definition

    🔹 UITableView

    A UITableView is a UI component in iOS used to display data in a scrollable list format (rows and sections).

    👉 Example:

    • Contacts list
    • Messages
    • Settings menu

    🔹 UITableViewCell

    A UITableViewCell is a single row inside a table view that displays one item of data.

    👉 Example:

    • One contact name = one cell
    • One message = one cell

    🧠 2. Key Concepts

    🔹 Table View Structure

    Table View
       ↓
    Section (optional)
       ↓
    Rows (Cells)
    

    🔹 Data Source

    • Provides data to the table view

    • Required methods define:

      • number of rows
      • content of each cell

    🔹 Delegate

    • Handles user interaction
    • Example: selecting a row

    🏗️ 3. UITableView Components


    🔹 1. UITableView

    Features:

    • Scrollable list
    • Supports sections
    • Reusable cells for performance

    🔹 2. UITableViewCell

    Features:

    • Displays text, images, or custom UI
    • Reused to improve performance

    📊 Diagram Description (for Exams)

    Draw:

    TableView
     ├── Cell 1 (Row)
     ├── Cell 2 (Row)
     ├── Cell 3 (Row)
    

    ⚙️ 4. Steps to Use Table View in Xcode


    🔹 Step 1: Add Table View

    • Drag UITableView into storyboard

    🔹 Step 2: Create Outlet

    @IBOutlet weak var tableView: UITableView!
    

    🔹 Step 3: Set Data Source & Delegate

    class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
    

    🔹 Step 4: Provide Number of Rows

    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 5
    }
    

    🔹 Step 5: Configure Cells

    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    
        let cell = UITableViewCell(style: .default, reuseIdentifier: "cell")
        cell.textLabel?.text = "Row \(indexPath.row)"
        return cell
    }
    

    🧩 5. Custom UITableViewCell


    🔹 Step 1: Create Custom Cell

    • File → New → Cocoa Touch Class
    • Subclass: UITableViewCell

    🔹 Step 2: Design in Storyboard

    • Add labels, images, etc.

    🔹 Step 3: Connect Outlets

    @IBOutlet weak var nameLabel: UILabel!
    

    🔹 Step 4: Use Custom Cell

    let cell = tableView.dequeueReusableCell(withIdentifier: "MyCell", for: indexPath) as! MyTableViewCell
    
    cell.nameLabel.text = "Student \(indexPath.row)"
    return cell
    

    🔄 6. Cell Reusability (Important Concept)

    🔹 Why reuse cells?

    • Improves performance
    • Reduces memory usage
    Old cells → reused → new data assigned
    

    📌 7. Important Rules / Tips

    • Always set dataSource and delegate
    • Use reuseIdentifier for cells
    • Avoid heavy processing inside cellForRowAt
    • Use custom cells for complex UI
    • Keep data separate from UI logic

    💡 8. Example App

    🎯 Contacts App

    • Table View shows list of names
    let contacts = ["Ali", "Sara", "Ahmed", "Ayesha"]
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return contacts.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = UITableViewCell()
        cell.textLabel?.text = contacts[indexPath.row]
        return cell
    }
    

    ⚠️ 9. Common Mistakes

    • ❌ Not setting delegate/dataSource
    • ❌ Wrong reuse identifier
    • ❌ Forgetting to return number of rows
    • ❌ Crashes due to force unwrapping custom cells
    • ❌ Not registering custom cell

    🧠 10. Best Practices

    • Use custom cells for complex layouts
    • Always reuse cells properly
    • Keep data in arrays or models
    • Separate UI and logic
    • Use MVC pattern

    📝 11. Likely Exam Questions

    1. What is UITableView?
    2. Define UITableViewCell.
    3. Explain the structure of a table view.
    4. What is cell reuse? Why is it important?
    5. Write code to display data in table view.
    6. What are data source and delegate methods?
    7. How do you create a custom table view cell?
    8. Explain reuseIdentifier in UITableViewCell.

    📚 12. Quick Revision Summary

    • UITableView → displays list of data

    • UITableViewCell → single row in list

    • Uses:

      • DataSource → provides data
      • Delegate → handles interaction
    • Key methods:

      • numberOfRowsInSection
      • cellForRowAt
    • Cell reuse improves performance

    • Custom cells used for advanced UI


    Previous topic 16
    Dynamically adjusting graphical layouts and creating universal apps
    Next topic 18
    Working with UITableView data source and delegate

    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 time4 min
      Word count624
      Code examples0
      DifficultyBeginner