如果我正确理解您的问题,您需要使用delegate。
在 ClassB.h
@protocol ClassBDelegate <NSObject>
-(void) hideSideBarButtons;
@interface ClassB: UIViewController {
__unsafe_unretained id<ClassBDelegate> delegate_;
}
@property (nonatomic, assign) id delegate;
-(void)hideButtons;
@end
----------
In ClassB.m
----------
@implementation ClassB
@synthesyze delegate = delegate_;
-(void)hideButtons {
[self.delegate hideSideBarButtons];
}
----------
In class MainViewController you need to sign up for ClassBDelegate event. Use this code in MainViewController.h
----------
@interface MainViewController : UIViewController <ClassBDelegate>
In ClassB.h
@protocol ClassBDelegate
-(void) hideSideBarButtons;
@interface ClassB: UIViewController {
__unsafe_unretained id delegate_;
}
@property (nonatomic, assign) id delegate;
-(void)hideButtons;
@end
In ClassB.m
@implementation ClassB
@synthesyze delegate = delegate_;
-(void)hideButtons {
[self.delegate hideSideBarButtons];
}
在 MainViewController 类中,您需要注册 ClassBDelegate 事件。在 MainViewController.h 中使用此代码
@interface MainViewController : UIViewController
当您初始化ClassB
时,MainViewController.m
您需要编写:
[classB setDelegate:self];
比您需要编写 ClassBDelegate 方法-(void) hideSideBarButtons
在您的MainViewController.m
文件中并禁用此方法中的所有按钮。例如(中MainViewController.m
)
-(void) hideSideBarButtons {
self.peBtn.enabled = NO;
}
希望能帮助到你))