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 PortalCOMP4126Table Views Uitablevie…
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
    4 min read
    Topic 17 of 38
    Topic Study Note Illustration
    17

    Using Table Views: Understanding UITableView and UITableViewCell

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

    πŸ“± 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 view and download past papers

    Click on Show Past Papers to load available exam papers.

    Reading Progress
    0%
    4mremaining
    624words
    Beginnerlevel
    On This Page

    No headings found

    Study Toolkit

    Subject Portal

    Mobile Application Development 2