The "controller" focuses on ownership and facade. External objects will talk to the controller, not to the controlled one. The only object that usually needs to talk directly to a UITableView is the UITableViewController . The controller typically owns the monitored object, and the controller must have at least the same lifespan as the monitored one.
The delegate focuses on behavior, strategy and observer. The object asks its delegate for guidance on behavior (should I show this data? What color should it be? Can I do this?). The object tells its delegate when interesting things happen (I was touched. I'm going to finish something. I had a problem.) The special delegate answers data questions (what data is on line 3?). They are called data sources.
In cases where the rest of the system is talking to the “controller”, it is usually not recommended to talk to the “delegate”. So, for example, it is usually advisable to have a pointer to the UITableViewController and send its messages from other places in the system. It is wrong to have a pointer to a tableView controller; You must work through the controller. On the other hand, if you have a pointer to an object, it is usually not recommended to request its delegate . If you need it, you have probably designed something wrong. (The most notable example is the [[NSApplication sharedApplication] delegate] , which you almost always have to talk to. AppDelegate is an application delegate, not a dump for global characters.)
If an object has a controller, the controller is almost always a delegate. To my rules, which you are talking about, when an object is both a controller and a delegate, then this is a controller.
It is possible that one object is the delegate of several things, especially if most of them are short-lived (for example, presenting warnings). It is not uncommon for a UIViewController delegate certain things.
Rob napier
source share