hidesBackButton / setHidesBackButton not working - ios

I have some problem in my application.
In my application there is a possibility to edit some information (something like iPhone's contacts). When you press 'Edit' button on right of navigation bar, "Back" button should hide, and "Cancel" button appear.
It working perfectly, when user press "Edit" button straight from ViewController.
But, when user creating a new advert, the view controller with editing should open, in edit mode. I call it this way:
VICarInfo * vc = [[VICarInfo alloc] init];
[vc setCurrentAdv:adv];
[self.navigationController pushViewController:vc animated:YES];
if (editMode) {
[self.navigationItem setHidesBackButton:YES animated:NO];
[vc btnEditClick];
}
And "Back" button didn't disappear.
I also tried to hide button in ViewWillAppear, ViewDidLoad or ViedDidLayout subviews, also unsuccessful.
Please, give me any advices, how to do it.
Thank you.

Use this :
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:[[UIView alloc] init]];

I know this is late, but I was seeing the same thing and found a solution.
It seems that hidesBackButton = YES interferes with setting the leftBarButtonItem(s).
Don't use hidesBackButton and you'll lose the overlay.
This seems like a bug, but Apple's own documentation is pretty hazy on the interaction of those two/three properties.

Try this one..
[self.navigationItem setLeftBarButtonItem:nil];
[self.navigationItem setHidesBackButton:YES];

Since iOS 5.0:
self.navigationItem.leftItemsSupplementBackButton = ?;
NO - having leftBarButtonItems hides the backButtonItem (default),
YES - leftBarButtonItems co-exist with the backButtonItem
There still seems to be an iOS 7 bug however, that hides (or not) the backButtonItem indiscriminately.

try on real device . showing custom image on real device . But not ios simulator . if you do test on simulator , you will see ios default back button .

Related

SWRevealViewController project in iOS

Note: Problem solved.
Here comes the story. I am using RevealViewController in my project. I am also hiding the navigationBars:
[self.navigationController setNavigationBarHidden];
My project can be seen in the picture below and the "menuButton" is implemented in the tabBarViewController.
Since the navigationBar is hidden due to my interface looks, all tabViews (HomeViewController) will not show the menuButton and the navigationBar as supposed to. I am not using panGestureRecognizer to trigger the menu aswell.
This means I have a problem to trigger the menu via a normal button in HomeViewController. The menuButton-event is placed in tabBarViewController.m:
_menuButton.target = self.revealViewController;
_menuButton.action = #selector(revealToggle:);
So I tried to call a method from HomeViewController to fire the button in tabBarViewController like this:
HomeViewController.m
- (IBAction) onMenuClicked: (id)sender{
tabBar = [[tabBarViewController alloc] init];
[tabBar setupMenu]:
}
tabBarViewController.m
-(void) setupMenu{
[_realMenuButton sendActionForControlEvents:UIControlEventTouchUpInside];
[_realMenuButton addTarget:self.revealViewController action:#selector(revealToggle:) UIControlEventTouchUpInside];
}
In this example I tried to make the realMenuButton and normal UIButton. Ive also tried as a UIBarButtonItem just to trigger the #selector(revealToggle:) But nothing happens in the app when I try to trigger the button from HomeViewController.
Not sure how I shall make this work. Any other Ideas or tricks? Please be specific if so! Regards
Yes, it will still work.
SWRevealViewController is just a subclass of a UIViewController, so you can use it at any point in the app:
By calling presentViewController:animated at some point.
By using it in a navigation stack etc.
Note that you can add gestures from SWRevealViewController to its content view controllers, which will alter the behaviour of used in a navigation view controller, but that's to be expected, and you still have full control over its behaviour.
Edit
The UI structure of your app is still not clear to me - it looks like you're trying to call revealToggle on an instance of SWRevealViewController when the VC in view is infact HomeViewController? How would this work, when SWVC is not even in view?
My best guess is that your UI structure should be as follows:
TabBarController --->(root)UINavigationController --->(root)SWRevealViewController.
Then, on your SWRevealViewController, set HomeViewController as the front view controller, and the TableViewController as the right or left view controller.
Do you mean like this?
it is possible. you can set the menu button in your tabBarController.m, like this :
UIBarButtonItem *menu = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:#"menu.png"] style:UIBarButtonItemStylePlain target:revealController action:#selector(revealToggle:)];
self.navigationItem.leftBarButtonItem = menu;
self.delegate = self;
For me, my initial view controller is the login screen (obviously I don't need reveal any VC here...). then when user tap the login button,
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:yourRootVC];
LeftMenuViewController *leftMenuVC = [[LeftMenuViewController alloc]init];
SWRevealViewController *revealController = [[SWRevealViewController alloc]initWithRearViewController:leftMenuVC frontViewController:nav];
revealController.delegate = self;
[self presentViewController:revealController animated:YES completion:nil];
I've tried it and it should work as normal. Even it isn't initial view controller

How to implement button Done in Navigation Controller between many tab bar?

Main screen in my app has 2 buttons. When click button 1, show ViewController1. When click button 2, show ViewController2. ViewController1 has 2 bar items. ViewController of each bar item has Back and Done button. Back is back to main menu, Done is used to hide keyboard. I want to control 2 these buttons.
I have 2 directions:
Add Navigation Controller at main screen. It has Back button. Button Done is implemented in ViewController of each bar item. In this case, button Done works not good when change tab bar. I loged and see that, first click in tab bar, it works correct, but click Item1->Item2->Item1, button Done in Item1 this time not correct, because it is still button Done in Item2 Controller.
How to fix in this case?
I hide Navigation Controller in main screen, implement Navigation Controller in Controller of each Tab Bar. In this case, button Done works good, but button Back can't move to main screen when click on it.
How to move to main screen in this case?
Code in AppDelegate.m:
UIViewController *cont = [[VCMainMenu alloc]initWithNibName:#"VCMainMenu" bundle:nil];
self.navController = [[UINavigationController alloc]initWithRootViewController:cont];
[self.window setRootViewController:navController];
Code in MainMenu.m, ViewDidLoad:
self.navigationItem.backBarButtonItem =
[[UIBarButtonItem alloc] initWithTitle:#"Back"
style:UIBarButtonItemStylePlain
target:nil
action:nil];
Code in MainMenu.m, buttonClick:
self.navigationController.navigationBarHidden = YES;
[self.tab setSelectedIndex:0];
[self.navigationController pushViewController:self.tab animated:YES];
Button Done in each class:
UIBarButtonItem *btnDone = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:#selector(btnDonePressed:)];
self.navigationController.topViewController.navigationItem.rightBarButtonItem = btnDone;
btnDone.enabled = TRUE;
btnDone.style = UIBarButtonSystemItemDone;
Thanks.
To hide the Keyboard you need to know which textView is firstResponder. You have to implement a dismisskeyboard method for each of your scenes.
Also, why are you coding all the navigation stuff? It would be much easier implementing them via storyboards and segues.
I hide Navigation Controller in main screen, implement Navigation
Controller in Controller of each Tab Bar. In this case, button Done
works good, but button Back can't move to main screen when click on
it. How to move to main screen in this case?
To do that, use
[self.navigationController popViewControllerAnimated:YES];
And as a sidenote #Marcal has a point, I think it might be better if you use storyboards and segues

Switching views from barbuttonitem? [duplicate]

This question already has an answer here:
Creating nib view from UIBarButtonItem?
(1 answer)
Closed 8 years ago.
So I've seen previous questions similar to this but they were of no help. I've read Apple's documentation too but I could not understand where I've gone wrong. AFAIK I did everything logically, but when I click on my done button on an UItoolbar overlay, the button can be pushed but it does not do anything. This obviously means it fails to acknowledge the written code. But how?
I want to bring up the .nib of "TableViewController" when a done button is clicked on my UIToolBar. But the below isn't allowing the click to bring up a new view. How do I rectify this? Please show me where I went wrong and what should be replaced and why.
//Here's the selector:
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:
UIBarButtonSystemItemDone target:self action:#selector(doneButtonPressed)];
Here's how I made my action. Btw, the uitoolbar has no nib, it's an overlay on the imagepickercontroller(camera mode).
-(void)doneButtonPressed {
TableViewController *tableView = [[TableViewController alloc]
initWithNibName:#"TableViewController" bundle:nil];
tableView.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:tableView animated:YES];
}
//Yet nothing happens when I click on my done button on my overlay. The button can be
clicked nothing happens. Please shed any insight pleasee!
This may not actually be the problem, but if the code your using above is how you're dismissing your Modal view controller it is incorrect. Other than possible improper usage I don't see any problems.
Use what you're using to present the Modal view controller, then to dismiss it use this:
[self dismissModalViewControllerAnimated:YES];

How can I disable the main toolbar when displaying a popover using modalInPopover?

I'm displaying a popover with the contained view controller having the modalInView property set. I need the user to enter a response here before continuing.
While this disables most of my user interface controls, it does disable the toolbar buttons on the main app. I don't want the user to interact with the application before selecting an item in the popover and closing it.
Am I missing something clever here - i.e. that would disable the toolbar by default? Why does it remain active? Is there some user interface guidelines that require it?
Should I just set the toolbar to disallow user interaction, or is that messy?
It seems like iOS adds the bar as a "passthrough view" for the popover, when you present it from UIBarButtonItem.
Just set to nil passthroughViews property of UIPopoverController after presenting it, like this:
[self.myPopover presentPopoverFromBarButtonItem:some_item permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
dispatch_async(dispatch_get_main_queue(), ^{ self.myPopover.passthroughViews = nil; });
Use -[UIPopoverController presentPopoverFromRect:inView:permittedArrowDirections:animated] instead, which doesn't enable toolbar interaction by default. For example, if presenting from a UIBarButtonItem with a customView property set:
[barButtonItem presentPopoverFromRect:barButtonItem.customView.bounds inView:barButtonItem.customView permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];`
What I found working best is what you mention as possibility in your question:
-(void)showMyPopover
{
....
self.myToolBar.userInteractionEnabled=NO;
[self.myPopover presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES]
}
- (void)popoverControllerDidDismissPopover:(UIPopoverController *)popoverController
{
self.myToolBar.userInteractionEnabled=YES;
...
}

Have a Button call a UITabBar Application on iOS

I am making an application that has a UITabBar and it works just fine, however I want to add a first screen which contains some instructions and a logo, then a button and when said button is pressed to show the UITabBar I've tried for a couple of days to do this on my own with no luck, I'm not even sure if it can be done, could anyone help me out? or give me a lead?
Try setting up the tab bar application, and then showing the first screen over it as a modalViewController. Inside your main app's viewController:
FirstViewController *firstViewController = [FirstViewController alloc] initWithNibName:#"FirstView" bundle:nil];
[self presentModalViewController:firstViewController animated:NO];
[firstViewController release];
When the button is pressed inside the modal view, call:
[[self parentViewController] dismissModalViewControllerAnimated:YES];
to get rid of it. You can adjust the animation style for the dismissal, or use NO instead to have it just disappear.

Resources