Using a UISearchDisplayController with UIViewController containment - ios

I have a UICollectionViewController that has a UISearchBar added as a supplementary view, with a UISearchDisplayController attached to it.
The search display controller works as expected, but when the collection view controller is added as a child to another view controller, the animation of the search bar to the navigation bar stops working. I believe this is the correct behaviour since the collection view controller itself doesn't has a navigation bar attached to it.
How can I force the search display controller to use the navigation bar of its parent view and animate to it?

Looks like this is not possible. I ended up giving up on UIViewController containment and adding everything to the same view controller.

Related

Smooth UISearchController navigation bar transition

I have a navigation controller with a root view controller that sets its titeView to a UISearchBar. Upon submitting their query, I push on another view controller which also has a UISearchBar populated with their query. If possible, I would like to keep this search bar in place and just transition the view controller below it. Is this possible with a navigation controller? Or do I need to make a custom container view controller.
One thing you can do is create a new custom view & do transition animation to the custom view upon submitting the query. This way will keep UISearchBar stay in place.

Top Bar on Collection View Controller

In my app, I have a collection view controller that is accessible by a modal type segue. What I am want is to have a top bar on the collection view controller. However, when I set a top bar in attributes tab of the collection view controller, it shows on the storyboard but not in simulator?
I think that What you are looking for is a UICollectionReusableView.
You should use UINavigationController.
If you're not using it, you could also add a UIToolbar.
That Storyboard section only sets the appearance in case you're using UINavigationController.

Edit parent view controller's title from child

I have app with UICollectionViews in UIPageViewController based on this tutorial for UIPageViewController, now I've embedded main view controller in navigation controller, and I want to change title of nav bar dynamically when in detail view, but how can I access it?
At first I've tried to embed in navigation controller Page View Controller, but nav bar wasn't displayed.
edit:
I've found out, that I can add navigation item to Time Snap Detail View Controller and set its title here, even though it's not visible in storyboard.
But how can I edit title in navigation bar, when I'm in Page View Controller?(In this case, on stack of the navigation controller is Main View Controller, which has Page View Controller as child view controller).
I tried this, and it's ok:
childVC.parentViewController.navigationItem.title = #"abc";
The parent in view controller is not working anymore. Looks like the only way is to save the parent in this child view controller's method and set it's title:
override func didMove(toParent: UIViewController?)
try this. it's working for me in almost same scenario
self.navigationController.parentViewController.navigationItem.title = #"sdfsdf.";

Adding Popover to current Navigation Controller hierarchy

I've seen a lot of other questions on here about adding a UINavigationBar to a UIPopoverController. All of the examples I've seen follow one of two patterns:
In the init or viewDidLoad method of the Popover subclass, you alloc-init a UINavigationBar directly, as suggested here. This method is a little hacky, and while it shows up nicely, if the popover is a UITableViewController, you have to mess with a bunch of things to make sure the navigation bar you just added doesn't overlap one of your cells.
Alternatively, a lot of post suggest creating a UINavigationController just before presenting the popover, as shown here.
With the second method, however, won't the popover be the only controller in the newly created navigation controller? And if my view that I'm presenting the popover from is itself already in a navigation controller, the popover will NOT be in that same navigation controller, correct? It seems to be that the more appropriate thing to do would be to add the popover being created as another controller in the navigation controller that already exists (and which the controller that presents the popover is already a part of). Is that possible? Or is there a reason why the navigation controller for the popover needs to be independent from the navigation controller for the presenting controller? Or am I totally missing something here?
You have many questions, young Skywalker. :)
Creating a UINavigationController and then embedding the controller you would like to present is the way to go.
Don't get confused by all the controllers involved here:
UIPopoverController is a construct that shows an existing UIViewController in an overlay like style. UIPopoverController itself even isn't a subclass of UIViewController. The name is misleading.
So UIPopoverController hosts another controller. In your case, we let it host a UINavigationController.
UINavigationController is a subclass of UIViewController. It is a container controller and can handle a stack of UIViewControllers.
On that stack we push one UIViewController: the one you want to display and garnish with a UINavigationBar. Since Mr. UINavigationController comes with a build in UINavigationBar, he's our friend.
There is no need to subclass UIPopoverController. You just keep one static reference to it around so you can dismiss the current open popover in case you want to present another.
It does not matter where you present the UIPopoverController from. It will always be a popover. Even if presented from an existing UINavigationController. Only if you use presentViewController: you will get different results depending on the controller you're presenting from (modal or pushed on top of the stack).
won't the popover be the only controller in the newly created navigation controller?
No, the popover will contain the navigation controller and the navigation controller will only contain its root view controller (which would otherwise have been added directly to the popover as its root).
You seem to be a little confused about the relationship between the popover and the popover root view controller...
the popover will NOT be in that same navigation controller, correct
Yes, correct. The popover is effectively a window floating above all other views
Or am I totally missing something here?
Maybe... The popover would usually be used for displaying something modal, transient and smaller than full screen size. Putting a navigation controller in the popover and adding views to it is the normal approach.
Adding a navigation bar to a popover isn't hacky. A navigation bar is just another regular view. That also means that using a UITableViewController with it, the navigation bar will overlap the table view, as the UITableViewController's view property just returns the controller's tableView property. If you want to add a navigation bar above a table view, without it overlapping the table view, use a regular UIViewController and add your navigation bar and table view the normal way. UITableViewController should only be used if your only view within that view controller is a table view.
Having said that, I do agree with others that just using a navigation controller without using its navigation features is the most common approach.

Modal Segue Into Navigation Controller with No Nav Bar

In my storyboard I have a view with a segue into a new view that's embedded into a Navigation Controller (so the segue points to the navigation controller). I have the segue set to a Modal transition, however when the new view is animating up, it contains the standard blue navigation bar above the view (which then animates out of view).
Here's what it looks like mid segue: http://i.imgur.com/3eqAQ.png
How do I make it so the modal view animates up but without the navigation bar?
I have tried hiding the navigation bar in the embedded view's init, viewWillAppear, and vieWillLoad methods and that doesn't work.
I event went so far as to create a custom subclass of UINavigationController and set the navigation controller in the storyboard to it.
Thanks!
This may sound pretty simple, but have you tried hiding the navigation bar immediately before the modal segue starts? I had this problem when presenting a modal view controller and adding a [self.navigationController setNavigationBarHidden:YES] immediately before the presentation did the trick for me.
I had almost the same problem, but I wanted to get a navigation bar for my modal transition, as it was always hidden.
There may be two ways for you to remove the navigation bar:
Make sure that your view controller is not embed in a navigation controller, as it would put one by default
Check the "Top Bar" attribute of your previous controller in the workflow and work with none/inferred values depending on your storyboard.
Regards

Resources