I have been struggling for some time with the strange behavior of navigation bar items. I have segmented control on the navigation bar (take a look at the image below)
where List button pushes table view controller with UISearchDisplayController. To show table view controller I use the code as it follows:
if (uiSegmentedControl.selectedSegmentIndex == 1 )
{
DetailsTableVewController* detailsViewController = [[DetailsTableVewController alloc]
initWithList:list];
[self.navigationController pushViewController:detailsViewController animated:YES];
[detailsViewController release];
}
Then to return back I use the following code:
[self.navigationController popViewControllerAnimated:YES];
Although I use the code above to go back to the previous controller when UISearchDisplayController is either active or inactive I have different behavior of the navigation bar items. When UISearchDisplayController is active ALL items disappear from the navigation bar
Does anybody know why it happens?
Thanks in advance.
Moved all navbar initialization code from viewDidLoad to viewWillAppear in controller and it solved the problem
Related
I have a uimenucontroller that I am using on a uiwebview. The menu controller works fine on simple text websites however on larger websites i.e. http://www.foodnetwork.com/recipes/giada-de-laurentiis/grilled-chicken-with-basil-dressing-recipe/index.html my custom menu item will not respond to touches. When tapped it highlights blue briefly then back to black, the menu is still displayed and myAction is nevere called. Sometimes if I click rapidly othe menu controller it will respond so I believe it may be something to do with the responder chain and or the size of the web page. I initialize the menu controller as follows:
// in view did appear:
UIMenuItem *item1 = [[UIMenuItem alloc] initWithTitle:#"Item1" action:#selector(myAction)];
[[UIMenuController sharedMenuController] setMenuItems:[NSArray arrayWithObject:item1]];
-(void)myAction
{
//do something
}
Thank you! I have been stumped by this for 2 weeks and am out of ideas...
How do I hide left button of the navigation bar I've created in the Interface Builder? In the Interface Builder, there is a check box Hidden for it, but I am not able to set it programmatically (UINavigationBar.topItem.leftBarButtonItem has no such property).
just make one IBOutlate for your uibarbuttonitem and them through that property hide that button
just like
#property (nonatomic,strong) IBOutlet UIBarButtonItem *hide;
now attache it to the left barbutton item of your navigation bar in xib
now use this code
hide.hidden = YES;
where ever you like to hide it and to show it
hide.hidden = NO;
just simple
happy codding
I'm creating a generic reusable UIViewController component that people can add to their applications. It requires a navigation bar at the top where it will add some buttons.
I can easily create a navigationBar and add the buttons, but if the developer using my component is adding the view as part of an existing navigation structure, they might end up with 2 navigation bars.
In other words, if my view is loaded with:
[self.navigationController pushViewController:controller animated:YES];
then it should not add a navigationbar and use what's already there. If the view is loaded with:
[self presentModalViewController:controller animated:YES];
then it should add its own navbar.
Without requiring the developer that uses my controller to do something like a useNavBar:YES, is there a way to do this automatically?
Something like a [self isRunningInsideANavigationController] or [self hasNavigationBar] would do.
You could use self.navigationController for that purpose. It will return nil or the navigationController.
I implemented the following code to show the navigation bar with a backbuttonbaritem.
[mapNavigationItem setTitle:#"Tracking"];
[mapNavigationItem setRightBarButtonItem:nil];
[mapNavigationItem setLeftBarButtonItem:nil];
UIBarButtonItem *stopTrackingBarButton = [[UIBarButtonItem alloc] initWithTitle:#"Stop Tracking" style:UIBarButtonItemStylePlain target:nil action:#selector(stopTracking)];
[mapNavigationItem setBackBarButtonItem:stopTrackingBarButton];
[mapNavigationBar pushNavigationItem:mapNavigationItem animated:NO];
[stopTrackingBarButton release];
The stopTracking button is displayed on the screen, but no title is displayed. When i click on the stopTracking button, it disappears and then shows the title.
Could someone please tell me whats happening??
Ok i think i wasnt clear enough,
I have a mapview with buttons in the tab bar, when the app starts the navigation bar shows 2 buttons, when i click on one of the Tab bar items, it should clear the navigation bar buttons and add a back button bar button item only. I am successful upto this stage.
But when i click on the BackBar button item, it disappears, and does not perform the action assigned to it.
FYI:
IBOutlet UINavigationBar *mapNavigationBar;
IBOutlet UINavigationItem *mapNavigationItem;
If you want to use a different title for your back button than the previous navigation title, then you need to change it just before pushing the new view controller and change it back again after popping it.
So something like:
self.navigationItem.title = #"Stop Tracking";
[self.navigationController pushViewController:mapNavigationItem animated:NO];
and in this class's viewWillAppear
self.navigationItem.title = #"Tracking";
Edit:
If you are not using the backbarbutton for taking the navigation controller back then dont set it as a backBarButton simply set it as left barButton item.
Plus it also seems like you are using same navigation bar for both tabs. not a good idea. Load both tab views from different viewcontrollers and add two different navigation bars to those views.
In my windows based applicaton, after login screen and registration page I added navigation controller for next two views. After pressing button present on second navigation window,again i want normal view controller and not navigation. But Its giving me navigation window with back button which takes me to second navigation window.
Can anyone plz tell me the solution??
You have a couple choices: you can truly eliminate the Navigation Controller entirely and replace it with another UIViewController (more complicated), or you can just push a new UIViewController that will not have a navigation bar/back button, and use that as the effective "root" view controller of your application from there on out. Without the navigation bar, your view controller will look like a "normal" view controller.
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.hidden = YES;
...
}