Ans : A delegate uses protocol and creates
a has-a relationship between two classes. Benefit of delegate is that we can
return something back to the owning class.
Coding of NSNotificationCenter :
Notification is like point to multi-point
communication. Notification is one way
of message transmitting way.
Delegates create relationship between
two classes. Notifications are used to send events to one or many classes.
We have to use delegate to specified
known object. Notification for all object.
Delegate is like talking over telephone.
Notification is like radio station.
[[NSNotificationCenter defaultCenter]
addObjserver:self selector:@selector(useNotificationWithString:) name:@”TimeOut” object:nil];
For BroadCast,
[[NSNotificationCenter defaultCenter]
postNotificationName:@”TimeOut” object:nil userInfo:dict];
-(void)
useNotificationWithString:(NSNotification *)notification
{
dict
= [notification userInfo];
}
To Remove observer,
[[NSNotificationCenter defaultCenter]
removeObserver];
No comments:
Post a Comment
Thanks