UISearchBar in navigation bar from UIBarButton in iOS7 - 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.

Related

How to add extra tab bar button in tab bar controller without adding view controller on that button in iOS

How to add tab bar item in tab bar view controller without adding a view controller with that and tap on that button no view controller are open. Tap on that tap bar button a alert will show.
On view did load create a UITabBarItem programmatically with a special tag. In your tab controller set the delegate to your view controller. On the method
- (void)tabBar:(UITabBar *)tabBar
didSelectItem:(UITabBarItem *)item
Check to see if the item has your custom tag and if so present an alert. If it requires a view to be linked with the UITabBarItem simply just set a view of another UITabBarItem for your alert view bar item.

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

iOS Left "More" UIBarButtonItem (in navigation controller) if UITabBar is hidden

In my ios5 application I have a TabBar, and for each tab I have a navigation Controller.
I have more than 5 tabs, but if I set HIDDEN to YES to my tab bar a UIBarButtonItem with text "More" will appear in my navigation bar (leftItemsSupplementBackButton is set to YES) to the left - only in rootViewControllers, and there's no way to get reference to this button.
Pressing this button it will go to moreNavigationController.
Any ideas how to hide this button?
The More Button is the back button standard will appear automatically if one of the > 4 tab bar item is selected, even if tab bar is hidden. The workaround to get hidden this button is to hide, only if view controller is rootviewcontroller, the back button:
self.navigationItem.hidesBackButton = YES;

iOS - Set UIToolBarItem on UINavigationController

I drag out a toolbaritem in storyboard and set it on my nav controller, but when I run my code it's not there, is there something I'm missing?
EDIT:
Tried setting it in code as well in my viewDidLoad method:
UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc] initWithTitle:#"Map" style:UIBarButtonItemStyleBordered target:self action:#selector(viewMap)];
self.navigationItem.rightBarButtonItem = rightBarButton;
Won't work either.
Here's how it's set up in my storyboard:
UPDATE:
Just found my problem. In my controller code when I update it's contents I change the right bar button item for a spinner and never set it back to what it had before.
UINavigationController already has a toolbar built in. It has a property toolBarHidden which is set to YES by default, which is why it is not normally seen. If you are using storyboard you can easily make the built-in bottom toolbar visible by checking the checkbox "Shows Toolbar" in the inspector when the Navigation Controller is selected.
See the UINavigationController documentation here for more details.
EDIT:
Ok, it sounds like what you are trying to do is add a right button to your view controller's UINavigationItem. To do this in storyboard, drag a "Bar Button Item" from the Objects Library onto the Navigation Item in your ViewController. You can then set the title/style/etc of the bar button item. If nothing still shows up when you run your app, make sure that your ViewController is connected properly with a segue to the navigation controller.
Also make sure you are adding the Bar Button Item to your view controller's Navigation Item, NOT to the View Controller itself. Here is how the setup should look in your storyboard:
To add an item to a navigation bar, you need to add a Bar Button Item to the Navigation Item contained in the view controller. Go to your storyboard, find the right VC, and find the navigation item (it's in the hierarchy shown in the navigation controller 'scene'). Just drag a Bar Button Item into that hierarchy underneath the nav item, or directly onto the navbar in the visual builder display.
The navigation controller only looks at your VC's nav item when that VC is pushed onto the stack; hence modifying the VC's nav item in viewDidLoad has no effect.
(I've done this programmatically before but I don't have the code with me, so maybe I'll add that later...)

Back button not appearing on pushed UIViewController

I have a UITableViewController. When I click on a cell I want to push a new view. This works fine, but the new view doesn't have a back button. Why is this?
TableViewCode:
if([[NSUserDefaults standardUserDefaults] boolForKey:#"isLoggedIn"])
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
ProfileViewController* profileViewController = [[ProfileViewController alloc] initWithNibName:#"ProfileViewController" bundle:nil];
profileViewController.message = [NSDictionary dictionaryWithObjectsAndKeys:cell.textLabel.text, #"user_login", #"default", #"message_source", nil];
switch(indexPath.row) {
case kUsernameRow:
[self.navigationController pushViewController:profileViewController animated:YES];
[profileViewController release];
break;
case kAboutRow:
break;
case kTOSRow:
break;
}
}
If your table view controller is created from nib, its default title is #"" (notice: not nil, but an empty string).
Back button has a bug where it doesn't display if title of previous controller on navigation stack is an empty string, so inside your table view controller, you need to set title to either nil or some string in code, or some string in Interface Builder (can't set it to nil there afaik).
From Apple documentation:
The bar button item on the left side of the navigation bar allows for navigation back to the previous view controller on the navigation stack. The navigation controller updates the left side of the navigation bar as follows:
If the new top-level view controller has a custom left bar button item, that item is displayed. To specify a custom left bar button item, set the leftBarButtonItem property of the view controller’s navigation item.
If the top-level view controller does not have a custom left bar button item, but the navigation item of the previous view controller has a valid item in its backBarButtonItem property, the navigation bar displays that item.
If a custom bar button item is not specified by either of the view controllers, a default back button is used and its title is set to the value of the title property of the previous view controller—that is, the view controller one level down on the stack. (If there is only one view controller on the navigation stack, no back button is displayed.)
Check if your Navigation controller has navigation bar enabled. Click on Navigation bar under Navigation Controller in IB and check if 'hidden' is un-ticked. If it is ticked, the navigation bar will not be shown and so the back button would be invisible too.