Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Both types of objects more or less behave the same way, it is a matter of what they do that is the question. </p> <p>A delegate type object responds to actions that another object takes. For example, the <code>UITableViewDelegate</code> protocol has methods such as <code>didSelectRowAtIndexPath</code> for performing actions upon a user selecting a particular row in a table.</p> <p>Whereas a data source type object gives data to another object. For example again, the <code>UITableViewDataSource</code> protocol has methods such as <code>cellForRowAtIndexPath</code> and <code>numberOfRowsInSection</code> dictating what should be displayed in the table.</p> <p>There is no hard difference between the two in terms of compilation, it is simply a coding style to make what objects do what very clear to the user of the code.</p> <p>EDIT:</p> <p>To answer your second question: if you want each alert to respond differently, you will need to write a different delegate for each alert. For example, if one of your alerts is a save confirmation alert (perhaps you are going to overwrite a file, and it pops up to confirm thats what the user would like to do), you would have an object such as:</p> <pre><code>@interface SaveConfirmAlertDelegate : NSObject&lt;UIAlertViewDelegate&gt; @end </code></pre> <p>And in the <code>@implementation</code> for <code>SaveConfirmAlertDelegate</code> you would implement the proper save feature depending on which button the user pressed in the alert. </p> <p>When you create an alert view, you specify what the delegate object should be, this does not have to be <code>self</code>. You could have your four delegates stored as different objects and set them on the alerts as necessary.</p> <p>I hope this clears things up</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload