【发布时间】:2011-01-19 17:06:41
【问题描述】:
我的协议:
@protocol ElectricalSystemEngineDelegate
-(void)didRequestMainMenu:(id)sender;
@end
我设计此协议是为了处理我的 rootView 控制器中模态视图控制器的解除。我的rootView控制器采用了这个协议,声明如下:
#import "ElectricalSystemEngineDelegate.h"
@interface RootViewController: UIViewController <ElectricalSystemEngineDelegate>
//other ivars & methods including instantiation of my modalViewController.
我使用的是开箱即用的:
-(IBAction)displayElectricalViewController
-显示模态控制器...工作正常。但是,我对如何进一步执行此协议以处理控制器的解雇感到困惑..
//The implementation of my root view controller.
-(void)didRequestMainMenu:(id)sender {
[self dismissModalViewControllerAnimated: YES];
}
显然,我使用规定的方法正确地实现了协议。我希望该方法在调用时关闭我的视图控制器。我还希望通过点击 modalViewController 中的后退按钮来调用它。
正如苹果文档所说,“在某些情况下,一个对象可能愿意将其行为通知其他对象,以便他们可以采取任何可能需要的附带措施。”我的目标是让我的 ElecticalViewController 通知其父级(RootViewController)它应该被解雇。应该通过点击后退按钮来触发解雇。对象如何完成这个通知?
【问题讨论】:
标签: iphone objective-c delegation