I've answered something similar to this earlier on (see question) with the same solution as you're currently using (see point 2 of my answer) but I thought of something like handling the flag not as a boolean, but to do it using an enum, so 1 variable will be enough.
typedef enum {
ViewControllerPushControllerNone,
ViewControllerPushControllerSettings,
ViewControllerPushControllerWhatever
} ViewControllerPushController;
@interface ViewController : UIViewController {
ViewControllerPushController _pushController;
}
@property(nonatomic, assign) ViewControllerPushController pushController;
@end
@implementation ViewController
@synthesize pushController = _pushController;
- (void)viewDidAppear:(BOOL)animated {
switch(self.pushController){
case ViewControllerPushControllerSettings:
// Push Settings controller
break;
case ViewControllerPushControllerWhatever:
// Push Whatever controller
break;
}
self.pushController = ViewControllerPushControllerNone;
[super viewDidAppear:animated];
}
@end
I think it's the best way you can get. This way, you keep the pushing of a controller in the main navigation controller, which is a good thing, and it's easy to manage I think.
EDIT You could also set the property to be a class, so you don't have to mess with the enum typedef. You could then also omit the switch statement, because you can then do something like:
- (void)viewDidAppear:(BOOL)animted {
if(self.pushController != nil){
NSString *selector = [NSString stringWithFormat:@"push%@", NSStringFromClass(self.pushController)];
[self performSelector:NSSelectorFromString(selector)];
}
self.pushController = nil;
[super viewDidAppear:animated];
}
- (void)pushSettingsViewController {
if(_settingsViewController == nil){
_settingsViewController = [[SettingsViewController alloc] init];
}
[self.navigationController pushViewController:_settingsViewController animated:YES];
}