How delegate call differ from normal method call
Whenever I wanted to inform something to parent class I have used delegate
instead of calling directly parent's functions. I have implemented like...
eg:
CustomClass *custom = [[CustomClass alloc] init];
// assign delegate
custom.delegate = self;
[custom helloDelegate];
In custom class, I have intimated parent like below....
-(void)helloDelegate
{
// send message the message to the delegate
[_delegate sayHello:self];
}
So my doubts , how it differs from direct call?. Setting delegate variable
with self is somewhat equal to giving the parent instance to child and let
the child call the function whenever required, how protocols helps here or
why we need protocols? what is the advantage?
thanx
No comments:
Post a Comment