2015-11-20 80 views
-1

比方说,我们有两个对象,大脑和啤酒瓶,大脑是我们用来管理整个车身应用的对象,它负责处理所有的重要任务,如粪便,吃,喝,睡等啤酒瓶附着在身体上,但它不知道大脑在想什么,同样,大脑也不知道啤酒瓶在想什么。委托具有实时例

大脑正在使用啤酒瓶的属性来满足自己在看电视时的自我满足感,但问题在于大脑如此分散注意力,以至于在啤酒即将用完时它不能注意。这一切都可能在灾难中结束,Brain需要知道啤酒何时是空的,以便它将身体送到冰箱并初始化另一个啤酒瓶。

大脑可以使用饮料功能降低啤酒瓶液体变量,但一旦液体达到0,大脑需要知道它,这是代表们开始行动的地方,我们可以使用啤酒瓶代表。大脑可以听取啤酒瓶代表告诉大脑瓶子是空的,我们所需要做的只是告诉大脑听取啤酒瓶,告诉它的代表是空的,大脑可以对它做出反应。

This well thought out and illustrated diagram shows all of this in action:

- (void)viewDidLoad { 

[super viewDidLoad]; 

UIActionSheet *actionSheet = [[UIActionSheet alloc] 
     initWithTitle:@"Delegate Example" 
     delegate:self // telling this class to implement UIActionSheetDelegate 
     cancelButtonTitle:@"Cancel" 
     destructiveButtonTitle:@"Destructive Button" 
     otherButtonTitles:@"Other Button",nil 

[actionSheet showInView:self.view]; 

[actionSheet release]; 
} 


- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex { 
NSLog(@"hello world!"); 
} 

.h file: 
@interface DelegateExampleViewController : UIViewController <UIActionSheetDelegate> 
{ 

} 

请告诉我该代码图像流如图所示啤酒瓶委托的例子。

回答