I have been reading an iPhone SDK book with a good foundation in Obj-C (Though all my practice came via console programs). I have been doing well understanding the topics presented but I reached a bit of snag when it comes to understanding delegates. It might just be me but I didn't get what the book was trying to convey (seemed a bit vague on the topic).
This is how I understand delegates and correct me if I'm wrong.
Say you wanted to display an alert message and the alert message has a button(s). I know that you want to create a delegate to perform actions based on something being done to the button(s). And the class your using as the delegate would need to conform to the <UIAlertViewDelegate> protocol. And in the class definitions you can have a method defined like...
too do something based on the button that was hit.
Now the UIAlertView class, does it contain an IBAction that sends
message to its delegate when one of it's buttons have been clicked? That's what I am a little confused on, I'm not understanding how the method in the delegate is being called upon.
Also would the only times we need delegates (in most cases) would be when you need to do something based on actions performed on user interface objects we don't have physical access to in IB (interface builder) like the buttons on a yet to be created Alert message? And in those cases you do, do the UI parts all have they're own protocols with possible methods that we can use in the delegate? If their would be other common cases where you would need a delegate, what would be some examples?
Sorry if I'm not very clear on everything (I could just be over thinking things), any help would be appreciated...
This is how I understand delegates and correct me if I'm wrong.
Say you wanted to display an alert message and the alert message has a button(s). I know that you want to create a delegate to perform actions based on something being done to the button(s). And the class your using as the delegate would need to conform to the <UIAlertViewDelegate> protocol. And in the class definitions you can have a method defined like...
Code:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
Now the UIAlertView class, does it contain an IBAction that sends
Code:
alertView:clickedButtonAtIndex:
Also would the only times we need delegates (in most cases) would be when you need to do something based on actions performed on user interface objects we don't have physical access to in IB (interface builder) like the buttons on a yet to be created Alert message? And in those cases you do, do the UI parts all have they're own protocols with possible methods that we can use in the delegate? If their would be other common cases where you would need a delegate, what would be some examples?
Sorry if I'm not very clear on everything (I could just be over thinking things), any help would be appreciated...