使用委托来解决这个问题。
Class A.h
@protocol MyDelegateClass
- (void)didLoadHomeView;
Class B.h
@interface MyViewController : UIViewController<MyHomeViewDelegate>
Class B.m
- (void)didLoadHomeView
{
[self.navigationController popToRootViewControllerAnimated:YES];
}
Class C.h
@interface MyCurrentViewController : UIViewController
{
id <MyLoadHomeDelegate> homeDelegate;
}
@property (nonatomic,assign) id <MyLoadHomeDelegate> homeDelegate;
Class C.m
-(IBAction) OnHome:(id)sender{
[self dismissModalViewControllerAnimated:NO];
if (self.homeDelegate) {
[homeDelegate didLoadHomeView];
}
}
,ModalViewController
即当前在类中的方法中RootViewController
被解除。关闭后,我弹出到导航堆栈中的当前根视图控制器,即主视图(firstViewController)。上面的代码在我的情况下完美运行。OnHome:(id)sender
MyCurrentVIewController
ModalViewController