Navigation title not showing on view with tab view controller, but "back" navigation works
Solution 1
please try this code, it might fix your table position
// Since in iOS7 the nav bar is translucent by default, so the table view starts at (0,0)
// you can either disable the translucent, which i don't recommend unless you really want to
// or just add 64 pixel on the top of your table view
[self.YOURTABLEVIEW setContentInset:UIEdgeInsetsMake(64, 0, 0, 0)];
and for the title, please try this
self.tabBarController.navigationItem.title =@"YOUT TITLE NAME";
Hope that helps..
Solution 2
Assuming your hierarchy as
NavigationController -> ViewController -> TabBarController -> ViewController1
-> ViewController2
-> ViewController3
If you want to hide navigation item in viewcontroller1, Add the following line
self.navigationController.navigationBarHidden = YES;
If you want to show title in viewcontroller2, Add the following line in
self.navigationController.navigationBarHidden = NO; //add this if you hide navItem viewcontroller1
[self.parentViewController.navigationItem setTitle:@"Title"];
If you want to hide backbutton and show title in viewcontroller3, Add the following line
self.navigationController.navigationBarHidden = NO;
[self.parentViewController.navigationItem setTitle:@"Contacts"];
self.parentViewController.navigationItem.hidesBackButton=YES;
Add this lines to viewdidAppear method instead of ViewdidLoad ,if you have problems inshowing when switching tabs.
edparry
IT Consultant. C# and JavaScript. Umbraco CMS. A little Objective-C for flavour. Always asking questions.
Updated on July 28, 2022Comments
-
edparry almost 2 years
I'm relatively new to iOS Objective-C development, and I've come across a problem that I can't find a solution to.
I have a
Table View Controller
, with two prototype cells on it, which populate fine. ThisTable View Controller
is one of threeTab Views
, and theView
that sends to theTab Views
has aNavigation Controller
. This means that the views within theTab Views
also have aNavigation
bar. The bar works fine, in terms of the "back" button working as expected, and the bar being in position. However, (at least on the List View) theNavigation Bar
isn't fully recognised - it's title doesn't appear, and the table cells start directly below the status bar, rather than below the navigation bar.Here's a couple of screenshots showing the problem: what appears in Xcode (what I expect to happen) And then on the device, this is what actually appears - the Back button in place and working fine, but no title field, and the table cells start too high.
I've tried adding
Navigation Bar
's andNavigation Items
, and while adding aNavigation Item
allows me to put a title on in Xcode, it still doesn't appear on the device in testing. I also tried to add anotherNavigation Controller
just before this view, but that didn't resolve the issue either, and it caused navigation problems further down in the heirachy.Hope I've been clear enough, please say if I need to post more information - I'm relatively new to Xcode and so not sure what exactly is applicable and what isn't. Thanks!
-
edparry about 10 yearsThanks for your answer (and edit), @Xu! The
setContentInset
worked, but unfortunately thenavigationItem.title
part didn't - I still just get the working back button, but no title. -
Xu Yin about 10 years@edparry would you mind show me how you add the navigation controller? i was testing locally, the title worked for me.
-
edparry about 10 yearsHi @Xu - I've uploaded a screengrab of my storyboard to Imgur, and annotated it to show how everything fits together. The problem I describe is with the three views linked to from the
Tab View Controller
- hope it makes sense. -
Xu Yin about 10 yearsCan you try this
self.tabBarController.navigationItem.title =@"fafda";
From your screen shot, seems like you have a navigation controller in tab bar controller. i tested exactly same hierarchy on my local, it worked