You don’t need to progress very far into iOS development before you need to deal with tables. This means: UITableView, and probably your own custom UITableViewCells. A common pattern is to have editable controls in those cells, so that the user can change data from the table itself. Now you’re faced with a problem:
How do you transfer that data back to your UIViewController so the app can use it?
You know how to do this with standard controls, like UITextFields, UIButtons, etc. But you have a UITableView with a bunch of UITableViewCells. They don’t really behave the same way:
- They’re dynamically constructed by your UITableView
- There are a variable number of them (usually)
- Getting access to them from the UITableView is not easy
- You don’t treat them the same way as “normal” UIViews, such as hooking them up using outlets in Interface Builder
But tear all this away, and your UITableViewCells are not special snowflakes, they are UIViews just like any other. You should treat them exactly that way. Then the answer becomes simple: you do the same thing that Apple does in their UIViews: use delegates. Here’s how.