Navigation Back Bar not changing from previous view title - xcode

I've been trying to change the text for my back button. I've changed everything from the previous view's back button text, to the visible view's back button text, to setting the back button equal to a new button and changing its text. Alas, all I get is the text of the previous views title.

You cannot set the title of the back button item, but you can replace the back button directly.
self.navigationItem.backBarButtonItem = UIBarButtonItem(title: "Back", style: .Plain, target: nil, action: nil)
The trick is to set it on the pushing view controller, not on the one displaying the back button item.
You can set it in viewDidLoad of your pushing view controller. If you want to custom the back button according to the pushed view controllers, set it in prepareForSegue.

Related

How to change the segue type of the storyboards

I've got this problem. I want the view controller to change when the player presses a specific button.
So I added a new "view controller" in the main storyboard, I customised it and then, holding the right button of the mouse, I dragged the button on the new view controller.
It appeared a little menu with different items:
show
show detail
present modally
present as a popover
custom
I've tried all of them, nothing changed (except for the last one: the app crashes).
The new view controller is like a moving window, if you swipe down you go back to the start menu.
What I want is that the new window replaces the first one.
Here's the problem
As you can see, the brown window is movable
As I understand you need to present view controller full screen.
You need to select "present modally" segue type. Then select segue in storyboard
And then select presentation style "Full screen"
Or you can make this programmatically:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let nextVC = storyboard.instantiateViewController(withIdentifier: "nextVC") as! NextVCClass
nextVC.modalPresentationStyle = .fullScreen
self.present(nextVC, animated: true)

Default Show Left Bar Button Item

I am using a show segue from a Table View cell to a "Detail View" because I am using a navigation controller, the Detail View comes by default with a left bar button to take me back to Table View. Because it is done by default, I cannot figure out how to access it, to change its propertys. More specifically it's color. I am using Swift in the most current Xcode. How do you access the default navigation bar button when using a show segue?

Popover not attached to anchor

I'd like to show a popover with it's arrow to a button that is part of my view (e.g. button is on my main view). I do this in Interface Builder storyboard editor (ctrl drag from button to popup contents view). Popup shows but not attached to the button. What I found for the buttons on the toolbar popover shows attached to the button as expected. Anchor property of the segue is set to this button. Xcode Version 7.0.1 (7A1001).
Edit: images of what I do:
1) Storyboard. First I ctrl drag from toolbar button to first controller, then ctrl drag to second controller from second button.
2) Correctly attached popover
3) Popover not attaches to in-view button.
You are right. Following method shows that the sending view is nil and by default contentview of window is used for popover.
So to fix just check if the positioningView is nil. if yes, set it to be button (create outlet for it).
Add following method to your viewController
- (void)presentViewController:(NSViewController *)viewController asPopoverRelativeToRect:(NSRect)positioningRect ofView:(NSView *)positioningView preferredEdge:(NSRectEdge)preferredEdge behavior:(NSPopoverBehavior)behavior
{
//do custom implementation (workaround)
[super presentViewController:viewController asPopoverRelativeToRect:positioningRect ofView:positioningView preferredEdge:preferredEdge behavior:behavior];
}

Standard Back Button in XCode (XIB)

I can't get the standard back button of iOS into a navigationBar because I can't find it in the Object Library, so can I do it with code or something else?
I just want the normal, standard, blue back button - you know which I mean.
To "automatically" have a back button you need first have a UINavigationController. Then you need to take a different UIViewController and add it as the root view controller in UINavigationController's init method:
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:someOtherViewController];
Be sure to also set a title for someOtherViewController, usually in it's viewDidLoad or initializer. I'll tell you why this is important in a second:
self.title = #"Some other VC";
Then take a second UIViewController and push it onto your navigation controller:
[navigationController pushViewController:anotherViewController animated:YES];
You now have two UIViewControllers on your navigation stack: someOtherViewController and anotherViewController.
Your view will now have a back button with "Some other VC" in it. This is the title of the view controller that was just moved out of view:
http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html
http://simplecode.me/2011/09/04/an-introduction-to-uinavigationcontroller/
I would also suggest reading up on how UINavigationControllers work and searching this site a bit more for customizing the back button. There are plenty of threads about it.
You can't add the back button yourself. The back button is part of the Navigation controller. If you embed a Navigation controller into your view(s), the back button will appear and be populated by the name of the previous view.
If you're using storyboards select your view controller, then in top menu choose "editor" -> "embed in" -> "navigation controller".
Edit: Here is an exmaple.
I'm running Xcode 7.2. This was driving me crazy, but I figured it out. Here are all the pieces you need to make the Back button appear (make a test project to prove it):
1) You have to have a Navigation Controller and it has to be set to be the initial view controller. So add the Navigation Controller, you will import two tables. Click on the Navigation Controller and on the properties list, check the box that reads "Is Initial View Controller". You will now see and arrow pointing to this view.
2) In our case we want a ViewController and not the included / connected TableViewController, so delete the TableViewController (RootController) and add a new ViewController.
3) Connect the Navigation Controller to the new ViewController by clicking on the top bar of the Navigation controller and orange circle with the arrow pointing left. Hold the Control button on your keyboard down and click and drag from the orange circle to the ViewController and let go. When given the list of options on how to connect the two views, select 'root view controller'.
Done! Now you the functioning navigation bar and you automatically get the back arrow on all segues added. Test this. Add another ViewController and connect to it with a button on the existing ViewController. Use the Control-click-drag approach from the button to the newest ViewController. Select the 'show' option for the new segue you created.
Run it. You'll see the back option has automatically appeared when you click the button and moved to the newest ViewController.
This is all provided by the Navigation Controller, but only when you make another controller the RootController. Happy navigating!

Check UINavigationBar back button visiblity

How would I check if my UINavigation's bar Back button is visible?
If it is not visible I would like to replace it with alternative functionality.

Resources