I'm running into what seems like buggy behavior. I have one UINavigationController, which contains a tabBarController within it. That tabBarController has more than 5 tabs, so there is a more button, which loads the MoreController navigationController. Of course, that creates nested navigationControllers, so I want to hide one of the navigationBars.
I do that by making my ApplicationDelegate a UINavigationControllerDelegate:
[[tabBarController moreNavigationController] setDelegate:[UIApplication sharedApplication].delegate];
And implementing:
(void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
navigationController.navigationController.navigationBarHidden = YES;
}
However, I end up with the Status bar overlapped:
Now, if I add some code to fix the frame manually, there's still some weird color overlay on the status bar, and now a black gap underneath the navigation bar. What gives?
Related
I know that it was a old question but i can't solve it. I made a Tabbar controller with seven tab item in storyboard with tab bar controller not in custom tab bar so, i want to hide an edit button on more section of tab bar.
for that i code as:
on application didFinishLaunchingWithOptions: method
_tabbarconroller.customizableViewControllers=[NSArray arrayWithObjects:nil];
and also add a method
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
UINavigationBar *morenavbar = navigationController.navigationBar;
UINavigationItem *morenavitem = morenavbar.topItem;
morenavitem.rightBarButtonItem = nil;
}
but it is not working in iOS7 please give me answer or any resource for this,
Use UITabBarController's customizableViewControllers property to make it nil :
yourTabBarController.customizableViewControllers = nil;
I have a UITabBarController in which I have 3 UIViewControllers (3 tabs).
I want to remove specific elements from each UIViewController view when the whole UITabBarController will disappear.
Is there any way to do this? I cannot use viewWillDisappear: in each UIViewController because this will remove these elements when the tab changes also.
Is there any way to handle this into viewWillDisappear: into TabBarController.m file?
You will be taking reference of viewController getting displayed. Use those references on back button to remove your specific elements from your controllers.
Hope you get it. Feel free to ask if any concerns ?
Or, you can use these delegate methods of UINavigationController :
// Called when the navigation controller shows a new top view controller via a push, pop or setting of the view controller stack.
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated;
I'm having a problem with EGOPhotoView library in my iOS app, and I hope someone of you can help me.
My app uses a NavigationController, but does not display the NavigationBar, because the navigation is managed my some custom control. The problem is when I show an image gallery with the EGOPhotoView library, which shows a NavigationBar appearing on tap: when I pop the EGOPhotoViewController, the NavigationBar is still displayed, but I don't want.
Can someone help me to fix this problem?
Thanks
You can set one of your classes (probably your app delegate) to be the navigation controller's delegate. Then, when the EGOPhotoViewController is popped, you can hide the navigation bar. E.g.
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated
{
if ([navigationController.topViewController isKindOfClass:[EGOPhotoViewController class]])
{
[navigationController setNavigationBarHidden:YES animated:YES];
}
}
I have implemented a custom version of a search form that behaves a lot like a UISearchBar with a scope bar (but is actually pieced together programatically for UI reasons). The screen loads with a TextField, you tap in the TextField and the navigation bar animates up off the screen, the text field moves up and a segmented control appears for filtering results.
Anyway, that all works, but when I tap on one of the search results my code pushes a new ViewController. The problem is that new controller gets pushed without a navigation bar (because I used [[self navigationController] setNavigationBarHidden:YES animated:YES] when switching to the search state).
I can show the navigation bar as the new ViewController gets pushed, or even animate it in as the transition to the new ViewController appears - but all those solutions look clunky. I want it to work as if you were using a UISearchBar (actually more like the email app) in that the restored navigation bar appears to just slide in from the right as if it's part of the child view controller.
I'm hoping there'll be a simple fix... thanks
For anyone that comes to this, the solution is to make your controller the delegate of the UINavigationController, then show or hide the nav bar in your delegate methods.
Your controller needs to implement the protocol:
#interface MYSearchController() <UINavigationControllerDelegate>
Then in -(void)viewDidLoad assign your controller as the delegate:
[self navigationController].delegate = self;
Finally, implement a method like this:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
if(viewController == self)
{
if(_searchState && ![self navigationController].navigationBarHidden)
{
[[self navigationController] setNavigationBarHidden:YES animated:YES];
}
}
else
{
if([self navigationController].navigationBarHidden)
{
[[self navigationController] setNavigationBarHidden:NO animated:YES];
}
}
}
I have an iOS app where there is a navigation controller as the root controller but at one part there is a tab bar to select between views in one of the nav bars. It looks similar to the iTunes app (navigation bar on top, tab bar on the bottom). I want the title of my navigation bar to change based on which tab is selected. I have two separate controller files for each tab. Here is what I have tried to use in each so far to fix this to no avail:
self.navigationItem.title = #"Title";
self.navigationController.navigationItem.title = #"title";
[self.navigationController setTitle:#"Live"];
[self setTitle:#"Top Title"];
How do I change the NavBar title based on which tab is pressed?
You change the title of the bar in the view controller that is currently being displayed.
So for example, in view controller A that you're showing in the tab controller, you might add:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:YES];
[self setTitle:#"A"];
self.tabBarController.navigationItem.title = #"A";
}
Same goes for B, C, etc.
In your ViewControllers that are in the tabs:
-(void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.tabBarController.title = self.title;
}
If the individual view controllers presented by the tab bar controller have their own navigation bars, then
[self setTitle:#"Foo"];
will set both the tab bar label, as well as the navigation bar title.
If the navigation controller is at the top level (i.e. the tab bar is inside the navigation controller), then you might have to set the navigation bar title's manually (and you'll want to do this in viewDidAppear rather than viewDidLoad, because these child controllers are not reloaded every time you switch), e.g.:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self.navigationController.navigationBar.topItem setTitle:#"Foo"];
}
Alternatively, you could do this navigation bar title adjustment in your UITabBarControllerDelegate method didSelectViewController.
If this doesn't do it, you might have to clarify your question, describing the hierarchy of controllers (e.g. is the tab bar controller inside navigation bar, or vice versa).
You can subclass the UITabBarController, set the delegate to itself, and use the delegate to set its title when the view controller is selected:
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
//change the title based on viewController that is selected
self.title = #"New title";
}
Just Two Lines of Code..Only thing is, you need to use viewWillAppear method
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.tabBarController.navigationItem.title = #"Your Title";
}
PS: Inspired from Above Answers...
UITabBarController *tabController = (UITabBarController *)self.parentViewController;
tabController.navigationItem.title = #"ABC";
This is working for me
From some R&D on internet
You have to pass the navigationItem up the chain.
The UINavigationController shows the navigationItem belonging to its topViewController which is UITabBarController.
The UITabBarController shows the navigationItem titles in its tabs. So what you need to do is make sure that the tabBarController's navigationItem is it's selectedViewController's navigationItem
So to recap:
UINavigationController title = topViewController.navigationItem.title
UITabBarController tabTitle =
selectedViewController.navigationItem.title
UIViewController title = navigationItem.title