How about if you use a flag that you switch on in viewWillAppear
and off in viewWillDisappear
and also in other relevant places e.g. in isMovingFromParentViewController
or what applies based on how you present it. Then you can flag your action when the observer triggers. Here is an outline.
@interface ViewController ()
@property (nonatomic) BOOL flag;
@end
@implementation ViewController
// Action triggered by observer
- ( void ) someAction
{
if ( self.flag )
{
// do it
}
}
// Switch on
- ( void ) viewWillAppear:( BOOL ) animated
{
[super viewWillAppear:animated];
self.flag = YES;
}
// Switch off
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
self.flag = NO;
}
@end
This is pretty simple. It is easy to maintain and debug and also if you need to at some stage switch on or off the action based on some other reason, it is easy to accommodate.
PS : You really need to show some code ... it is difficult to give more specific answer without you giving any code.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…