题
我的协议:
@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
-to显示模态控制器...工作正常。我,然而,混淆关于如何使用该协议控制器的手柄解雇的执行继续进行..
//The implementation of my root view controller.
-(void)didRequestMainMenu:(id)sender {
[self dismissModalViewControllerAnimated: YES];
}
显然,我正确地通过使用规定的方法实现的协议。我想的方法调用时解雇我的视图控制器。我也希望它通过在modalViewController后退按钮的敲击被调用。
随着苹果文件说,“在某些情况下,对象可能愿意告知其行为的其他对象,使他们可以采取任何抵押品的措施可能是必要的。”我的目标是为我ElecticalViewController通知其父(在RootViewController的),它应该被开除。这应该被解雇通过点击返回按钮来触发。如何对象完成此通知?
解决方案
您需要id <ElectricalSystemEngineDelegate> delegate
属性添加到您的ElectricalViewController。
然后,你需要创建ElectricalViewController后自(RootViewController的)分配给该委托。
然后调用[委托didRequestMainMenu]当要处理掉ElectricalViewController。
然后,你需要创建一个方法didRequestMainMenu你RootViewController的。
不隶属于 StackOverflow