Search code examples
iphoneiosobjective-cuitableviewios6

Understanding what happens and why you need a delegate and source for table views


I have been practicing with table views and I know how to create them but I would like to have a better understanding about delegate and source when creating table views.

Can someone explain the need for a delegate and a source when creating table views?

Why do you need them?

What is happening when you connect delegate and source to File’s Owner or ViewController and why they need to be connected?

I guess I need a general explanation about delegates and source and what happens when you connect them to File’s Owner or ViewController?


Solution

  • The delegate and data sources allow the tableview to conform to the MVC design pattern, which is a recurring design pattern in Cocoa and Cocoa Touch.

    The TableView itself provides the [V]iew part and the delegate provides the [C]ontroller part while the data source provides the [M]odel part.

    When you connect the delegate and datasource in the NIB file you are creating this connection visually; you can just as easily do it programmatically.