1

According to the Model-View-Controller pattern, applied heavily in Cocoa Touch, UIViewControllers should always handle the logic behind how a concrete UIView in the scene behaves.

I am curious as to how Apple implements it's UITableView class while keeping in line with this philosophy. Especially since UITableView inherits from UIScrollView and UIView in turn.

When you add a UITableView to one of your classes, does it have a UIViewController handling the way it behaves in the background? I know that a UITableViewDelegate is in charge of telling the table how many rows it should have, etc. But what about it's inner workings?

1 Answer 1

1

I'm gonna take a wild shot here, because I'm not sure I really follow your question. When you add a UITableView, you HAVE to have a controller associated to it to control how it handles and renders. Either a UITableViewController or a UIViewController that implements UITableViewDelegate and UITableViewDatasource. If you don't there's no way you can control what it does.

Sign up to request clarification or add additional context in comments.

5 Comments

Yes, I am aware of this. I guess what I'm asking is for example, who does the geometric calculations that determine how the UITableView actually moves? Who is in charge of actually calling the delegate methods?, etc. Does this responsibility belong to the actual UITableView class?
Remember that the drawing is done in the drawRect method that is present in the UIView class, so it is the view itself that handles how they draw. So all the layout code is present is the view, the controller tells it what it's gonna draw, i.e. the data, and how to respond to user action.
Doesn't this break the principle of MVC? Shouldn't a UIViewController, for instance, tell a UITable when to call the method in it's delegate UIViewController?
No, because you are separating drawing and view code code from business logic code.
It's a clear division of labor. The Model handles data access, Controller handles business logic, and View handles presentation of the data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.