What is M and what is V and what is C. in checklist app?

Hi,

I am really sorry but the more I read the chapters the more confused I am getting, now when I read Chapter 10, and try and find out what is M and what is V and what is C in the below code , I have no idea and I do not know why the same method with different arguments is being called again and again , please guide… the code is below —

import UIKit

class ChecklistViewController: UITableViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
    }
    
    // MARK:- Table View Data Source
    override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 100
    }
    
    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCell(withIdentifier: "Checklistitem", for: indexPath)
        
        let label = cell.viewWithTag(1000) as! UILabel
        if indexPath.row % 5 == 0 {
            label.text = "Walk the dog"
        } else if indexPath.row % 5 == 1 {
            label.text = "Brush my teeth"
        } else if indexPath.row % 5 == 2 {
            label.text = "Learn iOS development"
        } else if indexPath.row % 5 == 3 {
            label.text = "Soccer practice"
        } else if indexPath.row % 5 == 4 {
            label.text = "Eat ice cream"
        }
        return cell
    }
    
    // MARK:- Table View Delegate
    override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        if let cell = tableView.cellForRow(at: indexPath) {
            if cell.accessoryType == .none {
                cell.accessoryType = .checkmark
            }
            else {
                cell.accessoryType = .none
            }
        }
        tableView.deselectRow(at: indexPath, animated: true)
    }


}

Hi @amitsrivastava, thank you for posting here! Sorry to hear that you’re getting confused. I’d like to help out but could you clarify what you mean by M, V, and C from the code below please? I looked at it but don’t know if you are referring to a line with the letter M or if you are referring to the design pattern MVC.

Best,
Gina

@gdelarosa - thanks , its was to MVC design pattern in chapter 10, I also do not understand the use of override keyword, does it mean all the methods are already there, are these methods predefined delegates, how will I know which one is for data and which one is for view , I am really sorry but its very confusing and complex …

Also I do not. understand the who is communicating via delegates and how ?

Amit

@amitsrivastava, it’s ok to be confused when it comes to coding! I can definitely relate. As for MVC related to the code above. The ChecklistViewController would be part of the “C” as the controller. The tableview will be responsible for talking to the data model (“M”) which is the rows of data and the view (“V”) such as the tableview cell. The image posted in that chapter gives a great visual representation (pg.360 for e-book).

Best,
Gina

1 Like

This topic was automatically closed after 166 days. New replies are no longer allowed.