Hide BackButton in UINavigation bar - iphone

i am pushing a View om RootView controller ,i get the navigation bar with back button which is navigate to rootviewcontoller,but i don't need this back button.i pout this code in the viewcontoller to hide the back button
self.navigationItem.hidesBackButton = YES;
so i get the hidden back button,but here is the problem,i need leftnavigationbar button to show something,when i write the above code ,the letbarbutton also hidden from the view.becz the leftbarbutton act as the back button.
My need is to block the letbarbutton to become a back button when push from the rootviewcontroller,i didn't need a navigation back to rootviewcontoller.But defenitly need leftbarbutton there for my need in the view.
How can it possible to do?.Please help me to do this.
Thanks in advance.

try this.
self.navigationItem.backBarButtonItem = nil;
it works for me

Why don't you just set the letbarbutton and add no action to it?

Related

How to connect/activate a bar button item?

Can anyone tell me how to relate the bar button item to switching the view so that when the button is pressed it will load the next view?
I'm a newbie and using storyboard for my app. any good reference appreciated
Yes. UIbarButtonItem is on top of the navigationBar. If click on the button it will swith to next view.UIBarButtonItem won't load view. just it will navigate to next viewController.

iPhone - quick Navigation bar question

I have a UINavigation bar in a few of my views without using a UINavigationController. So i dont use the navigation controller to push new views, I load new views again which have a "static" UINavigationBar at the top.
So currently the navigation bars just show the title of which ever view the user is looking at, they have no other function.
In some of my views I have a requirement to have a back button, about 3 views out of 10.
So I was wondering if it is possible for me to insert a back button that states back and goes back to the previous screen for just these 3 views, so I would have to be able to insert the back button and also detect when it was pressed.
Can I do this with my current set up or do I need to go back and create a view with a UINavigationController and use that to push and pop my views and somehow suppress the back button on the 7 screens that I dont want it to display on?
EDIT:
I've tried the following way:
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:#"Back" style:UIBackButtonItemStyleBorder target:nil action:selector(myaction)];
[navItem setBackBarButtonItem:backButton]; //Doesn't work
[navItem setLeftBarButtonItem:backButton]; //Works but lacks the back arrow style of the back button
[backButton release];
So I can add a button but it doesn't look like the back button, is there a way to make it look like the back button or should I scratch and just use a UINavigationController? And if I do how can I suppress the back button when I dont want one?
You can if i get you correctly. Just add a custom button to the navigation as leftBarButtonItem or backBarButtonItem and give it a custom button press action. in the button method you can remove this view and show your previous view. But that said the better way is to use normal UINavigationController if your app has Navigation bar in all screens.

iPhone: capturing back button event

Greetings,
I have the following code for capturing the back button's event:
[self.navigationItem setBackBarButtonItem:[[UIBarButtonItem alloc] initWithTitle:#"Logout" style:UIBarButtonItemStylePlain target:self action:#selector(doLogout:)]];
And here is my doLogout:
-(void) doLogout:(id)sender{
NSLog(#"hi");
}
Everything compiles and runs fine, and the back button text is changed to "Logout".
The only problem is that my doLogout function is never called!!!
What can I do? I've been stuck on this for an hour now... ;(
Many thanks in advance,
The official doc:
When this item is the back item of the navigation bar—when it is the next item below the top item—it may be represented as a back button on the navigation bar. Use this property to specify the back button. The target and action of the back bar button item you set should be nil. The default value is a bar button item displaying the navigation item’s title.
Instead of trying to catch "back button event" why no just just try overriding UIViewController viewDidUnload?
Instead of setting backBarButtonItem on the top view controller, what you could do is set the leftBarButtonItem on the child view controller. This can be any arbitrary bar button item and all action messages should be delivered as normal. Because this takes place of the back button, you have to make sure you manually pop the child controller in one of the action methods.

How to disable UINavigationController?

I have a navigation controller-based app in which I would like to temporarily disable the navigation controller (top left button) at a certain point in the app so that the user can't get out of the view while I'm uploading a file. Is there a way to disable the "back" button so that users can't get out of the view?
You could hide the navigation bar entirely with
- (void)setNavigationBarHidden:animated:
in the appropriate views.
I don't know of an Apple-approved way to disable or otherwise interact with the back button.
In the view controller pushing into the view where you want to hide the back button (NOT in the view controller where you want the back button hidden), do:
self.navigationItem.hidesBackButton = YES;

How to display back button in nav app?

I'm pushing a tableview in a navigation based app. The pushing view (viewOld) and pushed view (viewNew) are both UITableViewControllers. I have given viewNew a title from viewOld. Once viewNew appears, I see the title but no back button on the left. Shouldn't a back button appear once you give the view (viewNew) its title?
I can click the empty space on the left of the navigation bar in viewNew and I go back to viewOld. But why is the back button not visible? I am doing this in OS 3.0 but I don't think the functionality or behavior of the back button has changed from previous versions.
Pushing viewNew from viewOld:
ViewNew * viewNew = [[ViewNew alloc] initWithNibName:#"ViewNew" bundle:nil];
viewNew = #"The new view";
[self.navigationController viewNew animated:YES];
[viewNew release];
The back button is the title of viewOld, unless viewOld's navigationItem has a backBarButtonItem set, which overrides it. If viewOld doesn't have a title and doesn't have a backBarButtonItem set, then the back button won't appear.
Note that if you want to set the backBarButtonItem, its target and action should both be nil.
I had the same problem: the Back button text was hidden but it worked when pressed on the left.
So I found this:
I just saw this the other day. What I found interesting was that touching in the area of where the back button should be actually worked.
I finally decided it had to do with the text of the back button. It pulls the text from the title of the parent view controller. If there is no title, there is no text for the button, and it seems Apple made it not display a button if there is no text. So, either specify a title on the parent controller, or if you don't want that, I believe you can specify the text that the back button will display (this is specified in the parent view controller, not the child).
That was all!