I would like to be conform with pattern MVC and i ask me, where the “cellForRowAtIndexPath” method must to go :/
Because, at the moment, this method is in the Controller File.
I would like to be conform with pattern MVC and i ask me, where
Share
You’re asking whether it should be in the Model (M) or Controller (C), I assume. And it’s an interesting question, because UITableView has two protocols:
Well, the UITableViewDelegate protocol is for the ‘owner’ of the view, which would be generally the Controller – I haven’t seen any code that assumes otherwise.
So then where should the UITableViewDataSource sit? This is the protocol that defines
Now, if the Apple developers assumed it would go in the Controller, why not just incorporate it into the UITableViewDelegate protocol? The documentation says this (with my bold):
So that seems to suggest it should sit in the model – but really by saying “mediates the application’s data model” it means it should sit in a Controller – but perhaps not the same controller that actually manages the
UITableView(via theUITableViewDelegateprotocol). It seems to me you have the flexibility to look at laying this out in a couple of different ways – however the general conclusion is that in 99% of the code I’ve seen it sits in the Controller which also is also theUITableViewDelegatedelegate.Here’s some Apple documentation on MVC: http://developer.apple.com/library/mac/documentation/General/Conceptual/CocoaEncyclopedia/Model-View-Controller/Model-View-Controller.html#//apple_ref/doc/uid/TP40010810-CH14-SW9