I have a method in a UIViewController to do things base on if it is currently appearing. I can put a BOOL flag to switch YES/NO when the viewDidAppear/viewDidDisappear is called but is there a better way/method to check?
Thanks.
I have a method in a UIViewController to do things base on if it is currently appearing. I can put a BOOL flag to switch YES/NO when the viewDidAppear/viewDidDisappear is called but is there a better way/method to check?
Thanks.
 
    
    The viewDidAppear method is your best bet.  I have seen some edge cases, though, where viewDidAppear/viewDidDisappear are not called depending on various factors.
Just because I enjoy the control and don't like any unknowns, I typically expose a method in my controllers that do all the setup when called and I would call this method when I know that my controller is getting called into action.
A rough example:
@interface MyController: UIViewController
- (void)reset;
@end
@implementation MyController
- (void)reset
{
    //Set some defaults, do some logging, etc
}
- (void)viewDidAppear
{
     [self reset];
}
- (void)viewDidLoad
{
     [self reset];
}
@end
Then...
@implementation SomeOtherController
- (void)someMethod
{
    [self.myController reset];
    //present self.myController using some logic
}
@end
