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!
Related
I've got a set of views embedded in a navigation view controller.
The way it works is that a button in the first viewController (embedded already in navVC) transitions w/"Show (e.g. Push)" which causes a "< Cancel" button text to appear in the top left.
Then I tap a cell which does another "Show (e.g. Push)" transition to a third vc which show "< Back" button.
I'm happy with the way the "< Back" button appears, but I want to remove the "<" from the "< Cancel" button so it just says "Cancel" with no arrow.
How can I override the back button to just show the title text, and also not pass that behavior along to further controllers in the series?"
Given the behavior you are describing, it sounds like it would make more sense to present the 2nd view controller as a modal in its own navigation controller. Then you can add Save and Cancel (or whatever you need) UIBarButtonItem buttons to the leftBarButtonItem and rightBarButtonItem of the 2nd view controller's navigationItem. The 3rd view controller can still be pushed as needed.
If you really do want to simply push the 2nd view controller but replace the standard back button then in the 2nd view controller you can set its navigationItem.leftBarButtonItem to a new UIBarButtonItem as needed. The left bar button item will be shown in place of the default back button.
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.
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.
I have a navigation Controller as the view of a popover, so that there is a navigation bar at the top.
On the first view there is no prompt for the navigation bar, so it remains at it's usual small size.
I then push the next view controller which does need a prompt and the bar expands, except behind the view, hiding the Title and Back button.
If I comment out the code in loadView, so that self.view is never set, then you can see the backbutton and title, but you can't click on the back button, as if it was behind another view.
I never had this problem in 3.2, only now in 4.2
Here you can set the size of popover using the following code:
self.contentSizeForViewInPopover = CGSizeMake(320, 460);
You need to set the content size of popover in view using this code and you can add this code in the viewdidLoad mehtof of the controller. Let me know if you still have any question.
I'm using a navigation controller to drill into a detail view when a cell is tapped. When I push my view controller onto the navigation controllers stack, I expect to see a back button that I can tap to pop the previous view off the stack.
The issue is that the back button isn't visible, but when tapping where it should be returns me to the previous view. What's the problem?
Ensure you have set a title for the master view - for example in viewDidLoad add this -
self.title = #"The Title";
Weirdly, if there is no title for the parent view controller on the stack, rather than show an empty back button, the iPhone will not display a button but will allow taps on the area where it should be.
This bugged me for a long time!
At least as of iPhone 3.0, you can also avoid the dreaded invisible back button by setting a title on the root controller's navigation item in your main window's nib (MainWindow.xib in wizard-generated projects).
Lets see if this helps you.
I had the same issue where I used a navigation based application and set up my search, rotation etc..
BUT, when I clicked on the table cell I was directed to the next view but that view did not have a back button present.
I tried to add a title to the back button but that did not work so this is what I did.
I opened the mainWindow.xib file and added a Bar Button Item to the group of other items inisde the window (where the file's owner is located). I then assigned an image to the button (you can add text here if you want).
Then I clicked on the Navigation Item and hit command 2 to open up the Navigation item connections
and chose the back bar button item and dragged it to the bar button item I wanted to use for my back button. And there you have it.