use of Delegate in iphone sdk -
Can anyone tell me how the representative works in the iPhone SDK ..... ??? What are the advantages of using a simple example and representative to use a representative.
Consider the widely used iPhone SDK examples:
-
You are running the animation The underlying system handles the animation for you. But it is natural that when you finish the animation, you want to do something (say, you want to activate a button or show some text when the animation is finished). Now how the animation mechanism will know what to do when the animation is over? All this is after your custom work. So you will configure a representative for the animation and the system will call that representative method when the animation is over. Obviously you will do your custom work in this representative method.
-
You have a text field and you want to know when the user has some taped or edited in the area. How do you know this? You will configure a representative for your text field and the predefined representative method will be called by the UTeadfield class when the specific field is edited or tapped.
-
Forget UIApllicationDelegate? Works on loading the system and running the app. How will this tell you that this initialization has ended and now you can run your code? This will call your app representative's Adfinish launching method.
-
You are making an asynchronous HTTP request after loading the data, your representative method will be called so that you can work with the data.
There are several more examples to use a representative, you must specify the representative object and sometimes the selector too. What is necessary to do, is dependent on what you are doing. That is, configuring an animation delegate is different than configuring a text field representative. But the general procedure is the same, you need to specify your representative object.
Example code for animation:
CatSession * animation = [Catrash animation]; [Set animation: delegate]; // Here the delegate is your representative object
After the animation has ended, your representative object's
- (zero) animation on the desktop: (animation) * Animation is finished: (BOOL) Flag < / Pre> will be called and you will optimize in this method.
Comments
Post a Comment