How can I hide the navigation bar when pushing a view controller? - objective-c

I'm making customized UIScrollView such like pinterest's two column view.
The scrollview should have search function. So I tried to use UISearchDisplayController but I can't because UISearchDisplayController implements only UITableView.
So, I created search display controller such like UISearchDisplayController. It's good. well done.
But I have a big problem. I can't implement completely behavior of UISearchDisplayController when go to detail view.
See below images.
this image is UISearchDisplayController's behavior on Simulator's Contact App.
Detail view have a navigationBar when pushed. but first view's navigationBar is hidden.
The UISearchDisplayController's behavior is good to transition view. Search view don't have UINavigationBar and detail view has UINavigationBar separately. but my controller can't do that.
I call setNavigationBarHidden:animated method try to hide navigation bar when touch UISearchBar on search view.
How to implement second image. any ideas?
sorry for my bad english :)

The search bar is different view, so here you need to call the below methods while view is navigating from one view to others.
self.navController.navigationBarHidden = YES;
or
[self.navigationController setNavigationBarHidden:YES animated:animated];

Related

Same UISearchbar in all child viewcontrollers of UINavigationController

I am wondering the following:
What is the best way to set up a searchbar that is available in all child view controllers of the navigation controller on the ipad (Hence in the entire application in my case).
A perfect example in which this is done is the IMDB application on the iPad, where each view controller with its presented views shows a search bar in the navigation bar that uses the same datasource.
I found the following post on this topic: Same UISearchBar for entire app?
However,I am not completely satisfied with the answer yet. I would like to know whether it is possible to show it in the navigation bar everywhere using either the function:
[self.navigationItem setTitleView:mySearchBar];
or:
[self.navigationItem setTitleView:mySearchBar];
searchDisplayController.displaysSearchBarInNavigationBar = YES;
at a specific location, hence not in each view controller. I thought of adding the search bar in the prepareforsegue function every time, but there must be a more convenient and nicer way.
Also, if you would suggest to work with container view controllers, how would this work with other navigation items? Can one adjust the size of the view UIsearchbar when more navigation bar items (buttons) are presented for a certain view controller?

Add a UINavigationBar and UIToolbar to modal UITableViewController

I'm creating an app that has a similar layout as the Apple Contacts app. I have created a UITableViewController and embedded it in a UINavigationController using a Storyboard. I then have an add button that opens a UITableViewController in a modal view. I have added a top bar to this view using the storyboard and it works pretty good. The problem is that it scrolls away when you scroll in the table. It should stick to the top.
Do I need to embed this modal UITableViewController in a UINavigationController as well to get the "sticky top bar"?
What's the preferred way of doing this? Just embed using the storyboard or just create one "on the fly" in the prepareForSegue method?
EDIT
I ended up just embedding the modal UITableViewControllers in UINavigationControllers using Storyboard.
Yes, you do need a UINavigationController that contains the UITableViewController to get what you aim for.
Personally, I would prefer creating it "on the fly" as you call it. But that is a matter of taste.
The way to do it in the storyboard is to have your modal view controller be a UIViewController rather than a UITableViewController. Add a view controller, then drag in a tool bar, and position it at the top. Then add a table view to take up the rest of the space below the tool bar. This will work correctly without scrolling with the table view.

UIPopoverController buttons beneath a table view

I was looking to implement something like the image below, and really have no idea how it's done and was wondering if someone had a quick design idea (no code is necessary or anything). Is it a footer view for the table view? is it some unknown footer view for a popover controller? Is it some way to integrate a toolbar from the UINavigationController 'into' the popover? I guess I could always create a custom view and display it 'like' a popover. Thanks for any help.
UIPopoverController will actually do a lot of that for you. If you set its content view controller to a UINavigationController, the contents of that navigation controller’s current view controller’s navigation item will display embedded in the top of the popover. I believe setting the view controller’s (not the navigation controller’s) toolbarItems will have the same effect at the bottom.
In this case, it looks like they wrote a custom popover controller; it doesn’t have an arrow attached, and the top of it is shaded a little differently from the standard UIPopoverController. But I’m pretty sure you can use the methods I just described to achieve a similar effect without having to roll your own popover.

UINavgationController and UITabBarController together

I am trying to create a view with a TableView in the center, NavigationBar on top, and a TabBar with 5 items. The TabBarItems will be attached to 5 different modal views. And the tableview can select an item and "navigate" to another tableview or detail view.
Following the Apple doc, I tried to create a NavigationController in a TabBarController in IB, but failed. I read all the posting regarding to this topic, and they all described a NavigationController inside one of the TabBarItem. But that is not what I want. The TabBarController and NavigationController are separate controller doing separate thing in the same view.
So I start wondering maybe it is a design issue. I should just use a NavigationController and add the TabBar as objects and not controller in the view.
Am I going the right track or is there a better way to combine NavigationController and TabBarController in IB to do the job that I want. Am I making sense?
If the tab bar is actually being used as a tab bar, it sounds like you want 5 navigation controllers, one for each tab.
If the tab bar is being used as a toolbar to hold buttons that bring up modal view controllers, push views onto the navigation controller, or other actions besides what a tab bar is intended for, use a UIToolbar instead. UINavigationController actually has toolbar support built in, just set its toolbarHidden property to NO and set the toolbarItems property on each view controller that can go inside the navigation controller to an array of appropriate UIBarButtonItems.

Can I use a UINavigationController as the detail view of a UISplitViewController?

I'm running into a problem with an iPad app where I would like to have UINavigationControllers in both of the views within a UISplitView. I've looked through other similar questions here, but most link to a tutorial online that doesn't completely solve the problem. Here's a 2-minute walkthrough to re-create the problem I'm having:
Create a New Project in XCode, starting from the Split View-based Application template.
Add the following NSLog statement as the first line within the DetailViewController's willHideViewController method:
NSLog(#"toolbar: %#", toolbar);
If you run the application now, the log will show that the DetailViewController's toolbar is alive and well. Now...
Open MainWindow.xib and expand the SplitViewController.
Drag a Navigation Controller from the library on top of the DetailViewController.
Expand the new Navigation Controller and change the class of the UIViewController within to a DetailViewController.
Ctrl-drag from the SplitViewController to the DetailViewController and assign it as the delegate.
Save MainWindow.xib and run the app again.
At this point, the detail view has a navigation bar and an empty toolbar. If you view the logs, you should find that the toolbar is null. Why is this? Am I missing some sort of connection in Interface Builder? Is the navigation bar the problem for some reason?
Unlike the tutorial at http://www.cimgf.com/2010/05/24/fixing-the-uisplitviewcontroller-template/, I would like to keep both the navigation bar and the toolbar (preferably with the toolbar at the top when in portrait and not visible when in landscape), so that I still have a functional "Back" button when the iPad is in portrait orientation.
Does anyone have any suggestions for fixing this problem? An example project with this sort of set-up would be ideal.
You can certainly use a navigation controller on the detail view of a split view controller. In fact, the iPad Settings app uses this approach. Probably the best way to get this setup is to create a new project in Xcode 4.x and select the "Master-Detail Application" template. It will generate a split view controller with 2 navigation controllers, one for the left view and one for the right view.
To your toolbar question, to keep things simple I would put a toolbar in the bottom. You can still put bar button items on the top navigation bar, although you can only put them in the left, middle, or right. If you need lots of items on the top bar, one way is to add a toolbar to the detail view and hide the navigation bar in the viewWillAppear event of the detail view class.
Here is an example on how to hide the navigation bar and show the toolbar:
- (void) viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.toolbarHidden = NO;
self.navigationController.navigationBarHidden = YES;
}
I've found the built-in UISplitViewController to behave badly when trying to combine it with most of the other built-in view controller subclasses. Matt Gemmell's MGSplitViewController is a lot more flexible and has worked pretty well for me, despite the odd glitches (though those are at least fixable as the source code is provided).