What exactly does delegate do in xcode ios project?
original source : https://stackoverflow.com/questions/7215698/what-exactly-does-delegate-do-in-xcode-ios-project
Examples: UITableView – a table view is just a control that knows how to render a list of cells. It handles all the heavy lifting of rendering, scrolling, etc… But, it has no idea how to load your data. So you implement a datasource delegate which has methods to get the cell data for a given row etc… That makes it easy on you. You just use the control and plug in the specifics for your data. The UITableView will do everything for you … just answer a few specific questions for. A delegate answers those few specific questions.
A text control – you add a text control to your view and voila! you can type in it and alls good. But what if you want to do something when they start typing or when they’re done typing? Well, the text control offers a delegate with methods that allow you to hook into the execution pipeline of the text control. It allows the text control to do everything for you and allows you to interject code where you need it. Many times, there’s way to interject code to make a decision on whether something is allowed. The control will call back and ask, should I be able to do x? You can interject code and influence the behavior.