这种情况的常见做法是使用委托。您FirstViewController
将有一个委托,然后您RootViewController
将为实例设置委托,并接收事件的信息。
第一视图控制器.h
@protocol FirstViewDelegate;
@interface FirstViewController : UIViewController
@property (strong) id<FirstViewDelegate> delegate;
@end
@protocol FirstViewDelegate <NSObject>
- (void)openMenu;
@end
第一视图控制器.m
- (IBAction)btnMenu:(id)sender {
[self.delegate openMenu];
}
主视图控制器.h
#import "FirstViewController.h"
@interface RootViewController : UIViewController
<
FirstViewDelegate
>
主视图控制器.m
-(IBAction)showFirstViewButtonClicked:(id)sender {
FirstViewController *firstViewController = [[FirstViewController alloc] init];
firstViewController.delegate = self;
[self presentViewController:firstViewController animated:YES completion:nil];
}
-(void)openMenu {
// this will be called when the btnMenu action is fired in the firstViewController
}