I've got a split view controller. Thanks.
A UISplitViewController sends splitViewController:willHideViewController:withBarButtonItem:forPopoverController: to its delegate when it hides the master view. You can set the bar button item's title to whatever you want. You can also save the bar button item (in an instance variable for example) and set its title later.
Related
I've created a view controller that's within the view controller hierarchy of a UINavigationController. This view controller contains a full-frame container view that displays the view of a child view controller.
I'd ideally like to display the items associated with the child view controller's navigation item (i.s., title and rightBarButtonItems) instead of the navigation item of the view controller that contains the container view.
My initial reaction is simply to set viewController.navigationItem = childViewController.navigationItem but navigationItem is read-only. My second reaction is to set the associated items themselves, e.g.:
viewController.navigationItem.title = childViewController.navigationItem.title;
viewController.navigationItem.rightBarButtonItems = childViewController.navigationItem.rightBarButtonItems;
With swizzling, I'm also able to detect when the child view controller's navigation item's properties are set and update accordingly. However, if the child view controller's navigation item's properties are updated without replacement (e.g., title changes text color, rightBarButtonItem is disabled), these changes are not reflected.
Is there any way of achieving the effect I'm looking for?
Hello sir instead of setting childviewcontroller navigation item you can set parentviewcontroller's navigation item.
I mean to say before loading child view controller you can set parentviewcontroller's navigation bar Item if you know childviewcontroller's navigatio bar item value.
I have one more question if you child view controller is inside container how does it have own navigation bar because it would be scrollable so better to set parent view controller's navigation bar before loading child view controller.
Turns out that my problem was elsewhere and that the approach outlined in my question works as desired. x_x
To make this answer more useful, here are more details of my approach:
I created a category on UINavigationItem and swizzled the methods -[setTitle:] and -[setRightBarButtonItems:] using Mattt Thompson's tutorial (http://nshipster.com/method-swizzling/). The swizzled methods simply post custom NSNotifications UINavigationItemTitleDidChange and UINavigationItemRightBarButtonItemsDidChange respectively.
In -[prepareForSegue:sender:] I extract the destination view controller of my embed segue and store it in a custom property childViewController on my view controller.
In the setter for my view controller's childViewController I add observers to my custom UINavigationItem notifications using the navigation item of my child view controller as the object.
When each of these notifications are received, I update the title and rightBarButtonItems of my view controller's navigation item, respectively.
The "elsewhere" in my own fix was that my child view controller wasn't updating its right bar button items when I thought it was, so it appeared as if the view controller presenting it wasn't obtaining its right bar button items.
In my app I have this storyboard:
and I would like to add a back button from the second table view back to the first. So I inserted a Navigation controller in order to have a navigation bar in the second table view ad I have created a segue with its identifier from the second table view to the first. But then how can I add a back button? I have tried to drag a button from the library into the navigation controller but it won't let me do it...I had already done this but in this moment I can't remember how.
Please can you help me?
In above image you shared you are making your tableview controller as root view controller.You have to kept your navigation controller on root. As you can see in attached image and you don't have to make back button manually as navigation controller has its own default back button.
This example is right how to make storyboard.Try it
self.navigationController?.navigationBar.hidden = false
In setting of UINavigationController set up like on screenshot
If you're using a navigation controller and its default navigation bar, you don't add an explicit back button--the navigation bar does it for you. You can add a UINavigationItem to your view controller, on which you set a title, back button title, etc.
Having a issue with navigationItem backBarButtonItem title on a embedded UIViewController.
Im embedding UIViewControllers in scrollview for pagination, and i want to change the back button title for localization when i push something on the stack of scrollview / pagination controller.
This is the code im trying to do in didSelectRowAtIndexPath:
QueryItemTableViewController *itemView = [self.app.storyboard instantiateViewControllerWithIdentifier:#"QueryItemView"];
self.scrollcontroller.navigationItem.backBarButtonItem.title = #"Test";
[self.scrollcontroller.navigationController pushViewController:itemView animated:YES];
The view QueryItemTableViewController is correctly pushed to the navigationcontroller but the title of the back button is still the title from the previous view.
Any suggestions?
Could you please update the title in ViewDidLoad method of the UIViewController which is being pushed.
Set the navigation title in the first one..
As you push to the next view controller. The back button gets set automatically, with the title you have set for the previous.
Now update the Title of the present view controller in the ViewDidLoad .
So simply these are the steps:
Step 1
always set the title for the current view controller in ViewDidLoad to keep uniformity.
step 2
push to the next UIViewController. Everything gets set automatically.
N.B: You wont get any back button for the first view controller (since it is the root view controller). If you need a back button type button there, simply customise a UIBarButtonItem and use it.
The title of the back button will automatically adjust for localization based on the user’s device language settings.
I have created a splitview controller in a storyboard that has a navigation bar across the top. I also have a master view with a tableview that when selected displays the correct view in the detail view controller.
How can I update the splitview controller's navigation bar title? I know I can access the master's nav bar through "self.navigationItem.rightBarButtonItem" but how do I access the main nav bar from this file?
Thanks
If you have a navigation bar across the top, then you can set the title like this:
self.title = #"this is my title";
If your title is fixed and doesn't change, then just add that line in your viewDidLoad method or where ever you would setup items in your view.
If you are trying to set the title programmatically, then it depends on which view controller you are in when you try to set the title. In the example above, it will set it for the view controller you are in.
If you want to set the opposite view controller navigation bar, you have a couple of ways to choose from depending on when you want to update it.
Generally though you would reference the opposite view controller directly using a delegate or indirectly using the splitViewController.viewControllers array.
it sounds like you already have a reference to the detail view controller. If so and you want to change its title from the master you can do so like this:
[self.detailViewController setTitle:#"New Title"];
hope that helps,
be well
I have a view that can either be shown via another view or via the More tableview list of more controllers.
In the first case, I added a More button on the Navigation bar to take them back to the More view list, but what is the code that I put on the More button to take the user back to the More list?
Thanks
If you want to customize your backBarButtonItem check this SO question.