UINavigationController custom titleView - uinavigationcontroller

I have a navigation controller with a root view controller for which i have the customised titleView instead of normal title for the navigation item.
If i pushed a new controller in it , the default back button title is "back", Since i have used custome titleView.
I want it to be different. I tried by setting the title in backbaritem of the root view controller, but no use.
I can create a bar button item in my pushed controller and i can set it as leftbar item, But i want it like a normal back button. [Pointing towards backward]
Is it possible to set title for the back button , if i have a custom titleView ?
Is it possible to create a bar button item as like as default back button.[Pointing towards back , other than plain,border...etc] ?
Regards,
Balaji R.

I got it.
Even though i have custom titleView for my navigation item, I can still set the title for the same navigation item where it wont be taken for the title display in navigation item . but it will taken as the title of the back button when some other controllers are pushed into it.
So , Now i'm having both title [Used for back title display] and titleView [custom view] in the navigation item.
Thanks,
Balaji R.

Related

UINavigationController and UINavigationItem

Apple's documentation on UINavigationItem states the following:
The managing UINavigationController object uses the navigation items
of the topmost two view controllers to populate the navigation bar
with content.
Why the topmost two view controllers instead of just the topmost? Is it just so that when you pop the view controller, it fades one item out and another in?
I think it's because the title of the "Back" button is (by default) the navigation title of the view controller just underneath the top one.
Navigation title: Title of top view controller.
Back Button title: Title of previous view controller.

SlideOutMenu remove Navigation Bar

I use SWRevealViewController for my project. Currently, the problem is that when the project starts, Navigation bar show with title of "MyApp". But, navigation bar disappears when I click on Home
If I add a Navigation Bar in view controller, there will be 2 navigation bars at first run. One navigation will automatically disappear when I click on Home link.
How to do to get the first image appearance when I click on Home link? I'm using Swift 3.
You could try set the navigation bar to not hidden in the viewWillAppear.
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(false, animated: false)
// ...
}
However I presume the reason the navigation bar is hidden is because the controller is being presented modally and not being pushed onto the main navigation controller. If this is the case, then you will need to probably do something with the SWRevealViewController and push the controller onto the main navigation controller.
Check out the Basic API usage for SWRevealViewController here and here is an alternative that has codeless storyboard implementation and is very easy to configure.
(Posted on behalf of the OP).
I'm not sure the way I solved is right or wrong. But, it works for me.
I remove default Navigation Bar by disabling the bar visibility. Then, I add new Navigation Bar in Home page. After I run the app, my new Navigation Bar appears when I press on the Home button.

One menu item to toggle between two states in WatchKit Context Menu

I'm setting up a Menu and Menu Items in Storyboard, and want one menu item to toggle between two states e.g. on/off, Celcius/Fahrenheit, etc.
However, control-dragging from a menu item to the interface controller doesn't let me create an outlet, but only has option to create an action. So although I can set up an action to toggle between two states, I'm not being able to change its title and image to show the current button state.
Is there a way to implement this correctly in WatchKit?
Yes, you can do it this way - whenever you want to toggle your state - clear menu items:
[self clearAllMenuItems];
and then set up new menu items:
[self addMenuItemWithImageNamed:#"myImage" title:#"action title" action:#selector(actionMethod)];

Storyboard UINavigation Controller Back Button Text

In XCode 4.5.1 creating a storyboard app with a Navigation controller, I am having a hard time trying to set the BACK button for any view controllers that are pushed. I'm using segue's and the view controller shows as expected. However I want to change the name of the navigation bar and back button dynamically and placed this in my ViewWillAppear:
self.title = #"Select Songs";
[self.backButton setTitle:#"Add"];
changes the title of the navigation bar but the back button still displays the NAME of the pushed window rather than the text "Add".
The Simulated Metrics are all Inferred. I also added a BarButtonItem to the black tray below the view in Xcode and wired up the backButton of the viewcontroller to the backButton, yet the text still does not appear.
Adding the following log messages also yield something interesting: (and yet the titlebar is updating correctly)
-(void) viewDidAppear:(BOOL)animated {
NSLog(#"%s %#", __FUNCTION__, self.navigationItem.backBarButtonItem);
NSLog(#"%s %#", __FUNCTION__, self.navigationController.navigationItem.backBarButtonItem);
}
2012-10-14 15:18:41.835 xxxx[2690:907] -[ViewController viewDidAppear:] (null)
2012-10-14 15:18:41.838 xxxx[2690:907] -[ViewController viewDidAppear:] (null)
The accepted answer is a hack, this is the way to do it...
Open StoryBoard
In Document Outline window find ViewController to which you want to
return to
Click on Navigation Item of that ViewController
In Attributes explorer change Back Button value to your custom tile
That is it, enjoy...
The back button will show the title of the previous view and if no title is set it'll show 'Back'.
So in your prepareForSegue method, you can change the title of the current view before the next view is pushed. The back button will then show whatever you set the title to.

How to identify the viewcontroller is clicked from More Tab or Separate tab in UITabBarController?

I have the navigationcontroller based viewcontroller and I overriding the root view controller navigation bar back button in to my custom segment control with different purpose. This navigation controller is placed one of the separate tab in the uitabbarcontroller. If this is used as the separate tab bar then no problem.
But if i use this navigationcontroller inside the more option in tabbarcontroller i am not able to come back to the more option list because of backbutton is overridden in my navigationcontroller.
My idea is add one back button only if my navigationcontroller is used more option tab otherwise i need to hidden the back button.
Please help me in this issue?
You can check if a view controller is in the 'more' section as follows:
BOOL isOnMoreNavigationController = [tabBarController.moreNavigationController.viewControllers containsObject:myViewController.navigationController];
From a UI consistency perspective it might be better to always show the back button in its standard position and move your custom buttons to some other place.

Resources