My application's main window contains a xib-based UITabBarController (fully configured in Interface Builder) that can also be presented modally (much like the Music.app "Add songs to playlist" modal view). The UITabBarController contains a number of UINavigationControllers which in turn contain subclassed UITableViewControllers. This is how I'm currently detecting if the subclassed UITableViewController is being presented inside a modal UITabBarController:
- (void)viewDidLoad {
[super viewDidLoad];
self.isModal = NO;
UIViewController *child = self;
UIViewController *parent = self.parentViewController;
while (parent) {
if (parent.modalViewController && parent.modalViewController == child) {
self.isModal = YES;
break;
}
child = parent;
parent = parent.parentViewController;
}
if (self.isModal) {
// modal additions, eg. Done button, navigationItem.prompt
}
else {
// normal additions, eg. Now Playing button
}
}
Is there a way to do this that doesn't involve walking up the parentViewController tree or subclassing all the intermediate view controllers to pass down the isModal state when they are initialized?