Why does the tabbar items label change when Pushing using UINavigationController? - uinavigationcontroller

I created UITabController with three tabs. One Tab has UINavigationController that pushes three controllers A,B, &C.
When I push segue from A to B or B to C, I change the titles on A, B, &C. Changing the title on A, B or C also changes the title of my third tab item in the main tabController. How can I make the tab bar items labels on the main Controller fixed?

I had the same problem and this thread fixed my problem: self.title sets navigationController and tabBarItem's title? Why?
You basically need to set your title in your viewDidLoad method in your UIViewController (which is displayed by the UINavigationController) like this:
self.navigationItem.title = #"Your Title";
instead of this
self.title = #"Your Title";

Related

iOS 13 and UiSplitViewController when presenting in Portrait missing DisplayMode Button

I have the same issue as described here
UISplitViewController portrait mode missing UIBarButtonItem
my SplitView contains two NavigationControllers which each contains TableViewController
the Detail tableview controller is the split views delegate there all generated in code
and have a delegate method splitViewController:willChangeToDisplayMode:
and splitViewController:willHideViewController:withBarButtonItem:forPopoverController:
for good measure
I have even tried to add the button my self if it is not there in splitViewController:willChangeToDisplayMode:
still no luck
any suggestions ?
Regards Christian
I Coded around the issue bu putting come code splitViewController:willChangeToDisplayMode: if the display mode is PrimaryHidden and the detail view controller don't contain a the splits view displauModeButtonItem in topmost navigationItem if the detail view controllers leftBarButtonsItems the I just manually add it
This is basically what #canderse said but I am showing the code. There is also a trick if you want your button to have a title. In your DetailViewController override the following method:
-(void)splitViewController:(UISplitViewController *)svc willChangeToDisplayMode:(UISplitViewControllerDisplayMode)displayMode{
//fix for missing navigation button
if(displayMode == UISplitViewControllerDisplayModePrimaryHidden){
self.navigationItem.leftItemsSupplementBackButton = true;
UIBarButtonItem *item=[svc displayModeButtonItem];
[self.navigationItem setLeftBarButtonItem:item animated:YES];
}}
For the button to have title, set your master view controller's title in awakeFromNib:
self.title = NSLocalizedString(#"Title", #"Title");
If you try to set the title in willChangeToDisplayMode, it won't work.

Why NavigationPage.SetBackButtonTitle do not use?

I have three Page(A,B,C) in my xamarin.forms project.I have a need that A push B,B puch C,When B push C,I want Set C page's Back Button'title to be other title.I use the method:
CPage cpage = new CPage();
NavicationPage.SetHasBackButton(cpage,true);
NavicationPage.SetBackButtonTitle(cpage,"A Page");
Navication.PushAsync(cpage);
But the C Page's BackButton' Title is also "B Page".Why?
B Page View
C Page View
The SetBackButtonTitle method is a bit unintuitive. If you want to set the title for C Page, you have to call SetBackButton title on B Page (the previous page)
In B Page constructor, after InitializeComponent, call SetBackButtonTitle
public BPage()
{
InitializeComponent();
SetBackButtonTitle(this, "Back Title");
}
and push the C Page normally as you would
Navigation.PushAsync(cpage);
this means, any page pushed from B Page will have the back button as "Back Title"
Change the title for iOS, the title use in any other page or the title is the same as class name. try to change the title of the page, its work for me.

UINavigationBar dims down when entering search

I've made an empty view controller wrapped in a navigation controller, and added a search bar using the navigationItem.searchController. A weird thing though, when tapping the search bar the animation works well but the navigation bar dims down as the entire screen.
This is NOT how it works on Settings and other places, i.e. the color of the navigation bar should stay the same.
Any ideas?
Some code:
- (void)viewDidLoad {
[super viewDidLoad];
UISearchController* searchController = [[UISearchController alloc] initWithSearchResultsController:nil];
searchController.searchResultsUpdater = self;
self.navigationItem.searchController = searchController;
...
}
Simply set dimsBackgroundDuringPresentation or obscuresBackgroundDuringPresentation to NO.
In your viewDidLoad method, add:
self.definesPresentationContext = YES;

How do I set up a Tab Bar Controller within an existing Navigation Controller?

I'm pretty new to iOS. I'm building an app and am running into an issue. I have a navigation controller with a table view controller atop its stack. When I select a row in that table view controller, what I'd like to see is a collection view with the following:
The nav bar with the name that appears on the selected cell as the navigation item title.
A collection view as the main interface
a tab bar with the collection view, and an imagePickerController
Here's what my code looks like:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NewTabBarController *tbc = [[NewTabBarController alloc] init];
UIImagePickerController *takeAPicture = [[UIImagePickerController alloc] init];
UITabBarItem *tabItem = [takeAPicture tabBarItem];
[tabItem setImage:[UIImage imageWithContentsOfFile:#"CameraIcon.jpg"]];
[tabItem setTitle:#"Take a photo!"];
UICollectionViewFlowLayout *photoFlow = [[UICollectionViewFlowLayout alloc] init];
PhotoCollectionViewController *photoHub = [[PhotoCollectionViewController alloc] initWithCollectionViewLayout:photoFlow];
[tbc setViewControllers:[NSArray arrayWithObjects:photoHub, takeAPicture, nil]];
NSArray *items = [[items accessor] allItems];
Item *item = [items objectAtIndex:[indexPath row]];
[photoHub setItem:item];
[photoHub useLayoutToLayoutNavigationTransitions];
[[self navigationController] pushViewController:tbc animated:YES];
}
Then in my PhotoCollectionViewController implementation I have:
#syntesize item;
- (void)viewDidLoad {
[super viewDidLoad];
UINavigationItem *itemHeader = [self navigationItem];
[itemHeader setTitle:[item itemName]];
UITabBarItem *tabItem = [self tabBarItem];
[tabItem setImage:[UIImage imageWithContentsOfFile:#"itemImage.jpg"]];
[tabItem setTitle:[NSString stringWithFormat:#"Photos of %#", [item itemName]]];
}
My problem is that when I select the cell, The collection view loads, and I can see the cells I have set up in the collection view, but the nav bar item has no title, and the tab bar item has "Photos of (null)" and no image. The "Take a photo!" text appears, but the image does not.
Do you guys have any idea how I can restructure this to make everything flow correctly. I must be doing something wrong in the way I'm utilizing tab and nav controllers.I don't want there to be any tabs until this stage in the app, which is 3 or 4 VCs in already. Should I be using a tab bar controller from the App Delegate onward?
The problem here is that you are pushing tab bar controller onto a navigation controller stack. The view controllers of a tab bar will have a navigation item, but their navigation items aren't shown when the view controller is on screen. Instead, the tab bar controller's navigation item is on screen.
You could use self.tabBarController.navigationItem, but then each view controller will have to modify the navigation item every time it's brought on/off screen, which is really messy.
If you're going to use a UITabBarController, I would recommend either presenting it modally, or having it be the root view controller on your UIWindow. It's tough to get it working right as a view controller in a navigation controller's view controller stack.
Your tab bar item not showing its name is a separate issue. It's because viewDidLoad is getting called before you set your item instance, specifically it's getting called when you call [tbc setViewControllers:[NSArray arrayWithObjects:photoHub, takeAPicture, nil]];
You can confirm this by breakpointing in view did load, where you'll see that item is nil. If you haven't already, you should overload your setItem: method in PhotoCollectionViewController, and have that method also update your UI.

UITabBarController/UINavigationController missing title

I have a UINavigationController and UITabBarController visible at the same time. Both the tab bar buttons and the navigation bar take their text from the title of the currently active view.
- (void)viewDidLoad {
[super viewDidLoad];
self.title = #"View Title";
However I want the different. In fact I'd like the navigation controller title to remain the same whichever view is being displayed.
Any ideas?
Many thanks.
Try This
UITabBarItem *tItem = [self tabBarItem];
[tItem setTitle:#"Title for tabbar"];
it won't change your tabbar title when you set the navigation title like
[self setTitle:#"Title for navBar"];
but I found sometimes it changes both tabBar and naviBar
then I insert the TabBar set titling code in -(void)viewWillAppear again to prevent
such happening
Thanks
You'll have to manually assign the title name, as you are doing above, in your other view controllers.
If your view hierarchy is more than two levels deep, be wary as the back button will look a little strange to the user (unless you override it). In fact, if every view has the same title, that may look strange to the user, period...
-(void)viewDidLoad{
[self setTitle:#"Custom Title goes here"];
}
This worked for me.
According to KwangBok Lee, I have tested, the best answer would be:
self.title = #"my settings";//changes both tabbars and navigationbars title
self.tabBarItem.title = #"settings";//only changes tabbars title
What I've found is... using
self.tabBarController.title = #"navTitle";
changes the navigation bar title, while
self.title = #"tabTitle";
changes the tab bar item title.

Resources