Adding a UISearchController to a Non-Table View - ios8

I'm having trouble with using the new UISearchController in IOS8. Every example I've found so far uses the search bar as the header view of a UITableView. What do you do when the search bar needs to be displayed somewhere else? For example, placing the searchbar outside the table to prevent it from scrolling? What about using it with something like a UICollectionView?
Am I missing something here? It doesn't seem like this should be that complicated.

Placing the UISearchBar in the titleView of the navigation bar, you can prevent it from scrolling when the tableview is scrolled.
self.searchController.hidesNavigationBarDuringPresentation = NO;
self.searchController.searchBar.searchBarStyle = UISearchBarStyleMinimal;
// Include the search bar within the navigation bar.
self.navigationItem.titleView = self.searchController.searchBar;
self.definesPresentationContext = YES;
UISearchController relies on searchResultsController which should be the view controller that manages the results of the search.
Make sure that the view controller pointed to by searchResultsController property updates based on the text in UISearchBar when the UISearchController is active. This way you can use the UISearchController with tableview or collectionview.

Related

Xamarin.iOS: how to add a NavigationBar to a View

I work on a Xamarin native app, where I show a modal view containing a list of countries.
I would like to know if there is a way to add a Navigation Bar to this view through the Controller?
Of course, the Navigation Bar will not contain the back arrow button, but a Title and a right button allowing to close this view.
Thanks for your suggestions.
The modal you present needs be wrapped in a UINavigationController rather than only being a UIViewController. This will give you a NavigationBar.
var modalViewControler = new MyModalViewController(); // UIViewController
var navigationController = new UINavigationController(modalViewController);

Prevent UISearchController from hiding view Navigation Bar in IOS8

I have a UIViewController embedded in a popover. This controller has two subviews, a UINavigationBar and a UITableView. I try to implement the new search API (as SearchDisplayControlled is deprecated in iOS8).
When I click in the search bar (displaying two scopes), everything is all right, and the navigation bar is still visible. But when I start typing in the search bar, the navigation bar disappears, replaced by a blank area. I tried to add self.searchController.hidesNavigationBarDuringPresentation = NO; in the updateSearchResultsForSearchController: method, but got no result. (note that the controller viewDidLoad defines self.definesPresentationContext = YES;)
Any idea to force navigation being displayed anytime?
I was seeing the same effect - in my case setting the property in viewDidLoad in my view controller made the navigation bar stick around:
- (void)viewDidLoad {
...
self.definesPresentationContext = YES;
...
}
When I'd previously set the same property from a class that was managing the search (initialized after -viewDidLoad had already been called on the VC), I saw the same behaviour of a blank nav bar that you describe.
This work for me
self.navigationController.navigationBar.translucent = true;

LaunchScreen.xib UINavigationBar & UITableView

I'm unfamiliar with Interface Builder. I typically do everything programmatically. How do I make the launch screen look like a UINavigationController as the window's root view controller with a plain-style UITableViewController as it's root view controller?
I tried adding a UINavigationBar and a UITableView to the LaunchScreen.xib provided by one of Xcode's iOS app templates, but the status bar remains transparent and doesn't automatically match the tint of the UiNavigationBar.
In Interface Builder, how do I set the tint of the status bar to match that of that of a UINavigationBar?
Rather than use Navigation Bar and Table View simply delete the View and drag in a Navigation Controller which comes with both and appreciates the location of the status bar. To get it to build simply delete the Table View Cell.

Xcode tableview hidden behind navigation bar

Can anyone please tell me how to fix the following issue.
I am building an iPhone app using Storyboard. I have a Navigation Controller as root view and off that a view controller. On this I have a few buttons that when clicked takes you to a table view controller. All fine and well, but when I link the buttons to their respective table views, the top navigation bar obscures the top cell in the table view controller.
Does anyone know why this is happening and how I can fix it?
Also it seems to have thrown off my layouts from the view controller from which they inherit.
See attached image for a better explanation perhaps.
I believe this is the intended behavior when using the translucent navigation bar. It's semi transparent specifically so that you can see items pass behind it (e.g. a table scrolling). If you don't want this, changing the navigation bar's style to opaque should solve the problem.
Since I wanted to keep the translucence, I just added a UIView between the navigation controller and the prototype cell (width of the view, height 60). That way the first cell in the table starts beneath the navigation bar but I can still see the scrolling underneath.
This is a bug/feature in IB when you use a translucent navigation bar, the content view runs under the navigation bar. For non transparent bars the content view begins after the bar. If your content view is a UIScrollView (UITableView is a descendent of UIScrollView) the content will be automatically scrolled so as to not be hidden under the navigation bar. So the problem only exist in IB when you run the app everything should be ok.
You just need go to the Navigation Controller properties, then Simulated Metrics, and change the Top Bar to be a Transluscent Navigation Bar WITH PROMPT. And that should be it. No need for that extra UIView

How to add a bar button item in interface builder?

I am really new to iPhone development and I need help setting up my views.
I have a view that is named FirstViewController.xib and a controller class for this view.
In my MainWindox.xib I have setup a root controller with a moveToNextView function that is connected to the options bar button item.
So when I click on this item the current view switches to the first view and I am able to swticht back. That works fine so far.
The navigation bar at the top of the screen from the MainWindow.xib is displayed in the first view, too. But when I open FirstViewController.xib there isn't any navigation bar defined (but on build&run it is displayed).
This is a problem for me because I want to add a save bar item to the first view. How do I solve that?
Assuming you have a UIViewController (or UIViewController subclass) that is a child of a UINavigationController. Note, I'm using storyboards so your results may vary when using xibs.
If you do not see a UINavigationBar on the interface, try manually changing the simulated metrics.
Drag a Navigation Item onto the view (anywhere). You should now have a place to enter the title in the interface builder.
Now you can drag Bar Button Items onto the nav bar.
You have to do it from code. Add to your FirstViewController class viewDidLoad method:
UIBarButtonItem *anotherButton = [[UIBarButtonItem alloc] initWithTitle:#"Save" style:UIBarButtonItemStyleDone target:self action:#selector(doSave:)];
self.navigationItem.rightBarButtonItem = anotherButton;
[anotherButton release];
Just drag a bar button item onto your nav bar in Interface Builder. Xcode automatically wires it up then you can use it like anything else...

Resources