I\'ve got an iPhone application with a UITableView
menu. When a row in the table is selected, the appropriate view controller is pushed onto the application\'s
I wasn't satisfied with the answers on this question so I posted my own: Reference to source view controller and destination view controller at the same time
The answer I got fixed my problem. It may work for yours too (though this question is pretty old, I figured this might help someone like me who read this post a half dozen times looking for a hint).
Here's what I did. I don't know if marker protocols are idiomatic objective-c or not, but I liken them to attributes like I'd use in c# so I have this marker protocol:
@protocol HidesNavigationItem
@end
I added UINavigationControllerDelegate to my AppDelegate. I'm not sure yet whether or not that's a good thing. I thought about keeping that implementation in another object, but for now, this is where I put it. Here's the implementation:
#pragma mark Navigation Controller Delegate
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[navigationController setNavigationBarHidden:[viewController conformsToProtocol:@protocol(HidesNavigationItem)] animated:animated];
}
This way, I can just set my marker protocol on my UIViewController implementation like so:
@interface MyViewController : UIViewController
If I don't have that interface, it puts it back.
Finally, in my appDelegate's application:didFinishLaunchingWithOptions: method, I wire up the delegate like this:
if ([self.window.rootViewController isMemberOfClass:[UINavigationController class]])
((UINavigationController*)self.window.rootViewController).delegate = self;
Now I get no black boxes and no Cheshire Cat. My solution was with regard to the navigation bar of course, but I'm sure it works the same for the toolbar. This is very similar to Danra's answer except that I get the black box without the "animated:animated."