UISearchBar + Search Display Bar in an UITableView within a UITabBarController - objective-c

In my iOS app I have the following :
Navigation Controller
Some other controller
UITabBarController
UITableView
UISearchBar + UISearchDisplayController
The behaviour I would expect to have is the search bar would move to the navigation bar when focused.
Instead currently it stays where it is : at the top of the table view.
I tried the same view without the TabBarController and the search works as expected : it moves to the navigation bar on focus.
Any idea how to fix this ?

Related

Putting a Navigation Controller inside a UIScrollView

I have a UIScrollView that houses three UIViewControllers so that I can swipe between them like the view setup in SnapChat.
In my ViewController on the very right of the UIScrollView I want the user to be able to select things and then navigate to a new page. So essentially I want the right-most UIViewController to be a Navigation Controller with a nav bar and and View Controllers I navigate to from this page should also have a nav bar and a Back button as the UIBarButtonItem in the top left as standard.
I went about it the normal way, just taking the View Controller and selecting "Embed In Navigation Controller" and looking at the storyboard it looks right, but if I run it, there's no nav bar at the top of the view controller.
I have the nav bar visibility set to "Show Navigation Bar" but still nothing.
Any help appreciated
Edit
The issue is more than likely to do with how I add the view controller to the UIScrollView which is as follows:
let settingsStoryboard = UIStoryboard(name: "SettingsView", bundle: nil)
let settingsViewController = settingsStoryboard.instantiateViewController(withIdentifier: "SettingsViewController")
self.addChildViewController(settingsViewController)
self.scrollView!.addSubview(settingsViewController.view)
So I'm only adding the view. So how would I add it as a Navigation Controller? Or can that be done?
The Problem you are facing is that you are adding your view controller directly inside the scroll view but you should add the navigation controller inside the ScrollView.
So go to story board create a StoryboardID for that navigationController which is attached to SettingsViewController and then replace the SettingViewController ID with your navigationController's Storyboard ID.
maybe use addChildViewController
- (void)transitionFromViewController:(UIViewController *)fromViewController toViewController:(UIViewController *)toViewController duration:(NSTimeInterval)duration options:(UIViewAnimationOptions)options animations:(void (^ __nullable)(void))animations completion:(void (^ __nullable)(BOOL finished))completion NS_AVAILABLE_IOS(5_0);

UISearchBar in navigation bar from UIBarButton in iOS7

I would like to have my search bar launched from a UIBarButton that I have added to my navigation bar from the storyboard. I have also added the Search Bar and Search Display Controller to the document outline in my view controller from the storyboard.
If I implement the code below in my viewDidLoad method the search bar will automatically appear in my navigation bar self.searchDisplayController.displaysSearchBarInNavigationBar = YES;
However, when I try and implement this in from a button click from my navigation bar nothing happens.
(IBAction)serachBarButton:(id)sender
{
self.searchDisplayController.displaysSearchBarInNavigationBar = YES;
}
The IBAction is properly hooked up to the view controller in the storyboard. Any code examples of how to launch the search bar from my navigation button click would be greatly appreciated.

hide navigationbar of uisearchdisplaycontroller when other viewcontroller is pushed

i have a uitableviewcontroller with uisearchdisplay controller. tapping on table cell pushes another view with some content and hides the navigationbar in the pushed view controller. the view controller has it's own uitoolbar, so far everything ok. the problem is that when a search result is shown and then tapping on the table cell view pushes the viewcontroller with uitoolbar with a navigation bar above it. so two bars on the pushed view. i dont want the navigation bar to be hidden. this code works if the viewcontroller is not pushed from search result
[self.navigationController setNavigationBarHidden:YES animated:YES];
what i'm missing using uisearchdisplay controller and hiding its navigation bar when other view is pushed?
I have redesigned my app. i dont use uisearchdisplay controller. instead i use uisearchbar and tableview which works perfectly.

How to change Statusbar on Modal Views iOS 6

I have the following constellation:
Main View (Custom UIViewController, no navigationcontroller or navigation bar), containing a button which segues modally to a second Table view controller, which is embedded in a Navigation Controller:
MainView -> Navigation Controller -> TableView
On the MainView the status bar is Black (no changes with iOS 6 - even when Status Bar is set to Default)
On the TableViewController the status bar should have Default Style (grey in iOS 5, Blue Tinted due to navigation bar in iOS 6).
In iOS 5 this was easy by the following lines of code in TableViewController:
if ([[UIApplication sharedApplication] respondsToSelector:#selector(setStatusBarStyle:)]) {
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
}
Running this under iOS 6 noting happens. How can I do this? I tried all possible Status Bar settings under project summary and in the plist (like described here: https://stackoverflow.com/a/12468689/1685971)
Also, in Storyboard everything looks fine. Running the app in simulator or on the device it looks different:
try this "hack":
You have to add a navigation bar to your first view controller. Then you have two possibilities.
1) Set the alpha value of the navigation bar to 0
or
2) Set the y-position of the bar to -43px (look here: http://moduscreate.com/tinting-your-status-bar-in-ios6-and-phonegap/)
EDIT:
To get the right colors you have to set the tintColor of the invisible UINavigationBar. So by default set it black. In your button action you have to set the tintColor to your navigationController.navigationBar.tintColor. At the action of your close button you need to set it back to [UIColor blackColor].
The first view controller must have a navigation controller/bar for the feature to work. The status bar does not change color throughout your app (in iOS6) but adapts to the navigationbar color of you starting view. If your starting view does not contain a navigationbar, the status bar does not adapt color.! (See http://i.stack.imgur.com/n9ubK.png)
You don't have to set the style for the navigation bar to your tableviewcontroller.
Try this approach.
1. Add navigation controller to the main view.
2. Set its property hidden to yes.
3. When you display tableviewcontroller, set the navigation bar property hidden to No
Navigation Controller -> bar hidden= yes ->
MainView -> bar hidden=no -> TableView

Tab bar controller not appearing correctly

I'm trying to connect Tab Bar Controller to existing part of my app, but when I do that it's "malfunctioning".
However when I run Tab Bar Controller part standalone as initial view controller it works properly like in the image below :
This is how app looks when it is run(correct behavior) :
However when I go to this tab bar controller from my main app this is how it looks like this:
My main app looks like this :
Scroll View contains
UIView 1
UIView 2
UIView 3
UIView x
Each view does something not related to this tab bar controller. Only one view view x tries to "visit" tab bar controller and display some data there, but it's not. Any ideas?
I have this tab bar controller identifier set to test, and I here is how I do that from my view x :
UITabBarController *newViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"test"];
[self.view addSubview:newViewController.view];
EDIT :
Entire app :
I'm creating views programatically. That's why I don't have any relationships/segues to the tab bar controller.
SOLUTION :
Change :
UITabBarController *newViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"test"];
[self.view addSubview:newViewController.view];
To :
UITabBarController *newViewController = [self.storyboard instantiateViewControllerWithIdentifier:#"test"];
[self addChildViewController:newViewController];
[self.view addSubview:newViewController.view];
You need to set a root viewController to the navigation Controller
Just don't do this. From the Apple UITabBarController referenece
Because the UITabBarController class inherits from the UIViewController class, tab bar controllers have their own view that is accessible through the view property. When deploying a tab bar interface, you must install this view as the root of your window. Unlike other view controllers, a tab bar interface should never be installed as a child of another view controller.
As I understand it means you must use UITabBarController only as a root view controller of the window. But you can alway use a general UIViewController and add UITabBar there.
(The view offset problem you've met is possible to be fixed, it will not follow the Apple guidelines however and not advised).