Add a toolbar to a tableView - ios

I'm using the XCode 4.3 "Master/Detail" template for the iPhone. At the ROOT level, this is a UIToolbarController. I want navigation and toolbars. The navigation is easy--the template already uses the self.navigationItem.leftBarButtonItem (and right) to add buttons, but I can't find a way to add useful toolbar items. I can add a toolbar (see below), but this gets added to the scroll view of the tableview, so scrolls up and down with the table contents--not very useful. The tableView.view has no superview which is where you'd think a tool bar should go. It has no window either! (all these properties are null).
That top navbar must belong to some view which is not scrolled, but what?!! Setting the toolbarHidden property of self.navigationController has no effect (setting the navigationBarHidden to YES does not hide the nav bar either).
Obviously something I don't understand here...
// this toolbar scrolls with the tableview contents!
INavigationController *nvc = [[UINavigationController alloc] initWithRootViewController:self];
nvc.toolbarHidden = NO;
[self.view addSubview:nvc.view];

Just highlight the navigation controller and then look at the attributes. check "Shows Toolbar" to unhide the toolbar that is already there.

Related

Why is my UITableview Y origin changing based upon the position in TabBarController

Upon clicking the button on the first screen the user is presented with view controllers contained within a tab bar controller. The view controllers have two tableviews in them, the first a top static table and a second table just below. The view controllers in the tab bar controller that are not within the "more" display correctly. If I go to "more" and select a view controller the view is displayed with the top cell pushed down.
If I go to the "more" screen, click edit, and move the order of view controllers in any way, view controller displayed through "more" display correctly. Upon leaving the "more" section the top table cell (top table) is not displayed.
It seems reasonable to me that there is an issue in the UI or storyboard, however nothing jumps out at me as the issue. I've tried both manually setting constraints and also using suggested constraints.
This sample project is available at https://github.com/propstm/NavigationStructureTest
I simply updated the constraints in the Two Table VC , then the issue was not there.
Disable Size classes,and delete the constraint(top tableView) of "vertically space to top layout guide",add pin top space to super view can solve the problem.
Maybe it's a bug of Xcode,see this.
I think it has something to do with the "more" controller provided by the TabBarController having its own navigation controller, and your storyboard set up to extend edges beyond top bars.
Although you are trying to hide the navigation bar, I think its done in the wrong place and should only be required when the item is being presented in the "more" controller. The way its currently implemented confuses the top layout guide, which seems to be left assuming there are two top bars even though one of them is hidden.
I was able to fix your demo project in two ways. By either:
1) Update the storyboard and turn off "extend edges" on the tab bar (and set the tab bar and top bars to be opaque):
OR
2) Simplify the viewWillAppear/Disappear and viewDidAppear/Disappear methods and hide the navigation bar when within the tab bar more controller:
- (void)viewDidAppear:(BOOL)animated{
//self.navigationItem.backBarButtonItem.title = #"HOME";
self.tabBarController.title = #"Entity List";
//Pretty activity indicator
[self.topTableView reloadData];
}
- (void)viewWillAppear:(BOOL)animated {
if (self.navigationController == self.tabBarController.moreNavigationController) {
[self.tabBarController.navigationController setNavigationBarHidden:YES];
} else {
[self.navigationController setNavigationBarHidden:NO];
}
}
- (void)viewWillDisappear:(BOOL)animated {
[self.navigationController.navigationBar setHidden:NO];
}
- (void)viewDidDisappear:(BOOL)animated {
}
This ensures the top navigation appears correctly without messing up the layout guide.

Navigation title not showing on view with tab view controller, but "back" navigation works

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. This Table View Controller is one of three Tab Views, and the View that sends to the Tab Views has a Navigation Controller. This means that the views within the Tab Views also have a Navigation 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) the Navigation 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 and Navigation Items, and while adding a Navigation 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 another Navigation 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!
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..
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.
I had the same problem, but what I did to create this problem was that my buttons action was connecting to the actual table itself and not the table Controller. I removed the modal action and created a new action to the table controller and it fixed the problem.
Try to click the Navigation Bar from your storyboard or nib.
Then add your title to the property.

UINavigationController transparent for UITableView underneath

I have a UINavigationController handling then navigation in my app. I would like the navigation bar to show the contents of the UITableView as I scroll up.
I can't seem to get it to be transparent. I have it set to translucent
self.navigationController.navigationBar.translucent = YES;
But still nothing. I'd like to add color, but I'll worry about that later. I've tried creating a subclass of UINavigationController and specify
self.navigationBar.backgroundColor = [UIColor clearColor];
self.navigationController.navigationBar.translucent = NO;
But again, no luck. This is what my interface builder looks like...
And this is what it looks like when I scroll the text up under the nav bar. Any suggestions?
Alright, I figured out a (seemingly simple) solution.
If you're using a UINavigationController to add a UINavigationBar to each of your views, this will work for making a transparent navigation bar.
Select the Navigation bar in your UINavigationController
Then, in the inspector bar (on the right), select "Clear Color". Tada! I'm a bit embarrassed I didn't try this sooner. Hopefully this will save someone else lots of time.
Try using a UITableViewController embedded in a UINavigationController, instead of a UIViewController. It'll adjust the insets for the iOS7 live blur automatically, so that the list content will show up under the Toolbar/NavigationBar on scroll.
I can't really make it out from your screenshot, but you can disable 'Hide Toolbar' in the parent NavigationController. You then don't have to add it separatly.

How to add a subview to a UINavigation Controller without losing navigation bar?

I have a SplitViewController which has two UITableViewControllers - one master/root one detail. Everything works swimmingly.
I have a UIView which is shown on the detail view controller before the user selects an item in the root view controller. It's set up like this:
[self.navigationController.view addSubview:makeSentenceHelperView];
[self.navigationController.view bringSubviewToFront:makeSentenceHelperView];
The detailViewController is set up like so:
UINavigationController *detailNav = [[[UINavigationController alloc] initWithRootViewController:detailViewController] autorelease];
Where detailViewController is a subclass of UITableView.
The problem is that this subView hides the buttons and navigation bar from the detail view controller's navigation bar - which is a problem when you launch the SVC in portrait mode (there's no way to select a root item with the root popup).
How can I present the view inside the navigation controller, so that the navigation bar and buttons appear in the detail view?
Don't make detailViewController a subclass of UIView, instead go with UIViewController. So your splitView array will contain a instance of UINavigationController(rootVC) and other of UIViewController (detailVC).
Add a toolbar on the top of detailViewController and in landscape mode left side will be covered by your UITableView of rootVC and you will be able to see toolbar where you can add some button to its right side (will probably serve as navigation bar..:) . Rest of the things can be handled by UISplitViewControllerDelegate.
To fix this I added a UINavigationController to my helper UIView, and added a UIButtonBarItem to call the popover for selecting a new item in the master view. It seems really simple in retrospect. The only tricky bit will be making the UIButtonBarItem hide when in landscape.

iOS - Toolbar not showing

Using the storyboard I created a new screen for a second View controller and added a Toolbar at the bottom. But when the view is shown, the toolbar doesn't appear. I'm using Segue to change views.
What could be wrong?
If you're using a Navigation Controller, make sure to tick "Shows Toolbar" and add the buttons there, not on a standalone toolbar.
In order to show only on some, you'll need 2 different views, one that will hide it and another that won't and add the following to the respective view's viewWillAppear:
self.navigationController.toolbarHidden = YES;
(Set to YES to hide, NO to show)
You can play around with the Simulated Metrics on the Storyboard so as to visually simulate the run-time effect by setting Bottom Bar to either None or Toolbar instead of inferred, as appropriated.
EDIT: Check this sample project I made.
Select the Navigation Controller in the storyboard. Under Bar Visibility, check "Shows Toolbar".
try this
self.navigationController.toolbarHidden=NO;
In the show the size inspector in the field autosizinf choose to bind to the top of the screen and remove the binding to the bottom of the screen.

Resources