"back" text displayed in iOS7 UINavigationBar when view title is long - objective-c

In my application,I need to show the previous viewController title to current viewController back title.
Its working perfectly in iOS6.
In iOS7,automatically the "back" title displayed other than the previous viewController title.
how to fix the issue in iOS7?

In iOS 7 you will not be allowed to set the back button's title to be any longer than 11 characters.
To avoid changing the title of the view controller, but to change the back button's title, you need to do this:
In the previous view controller (the one that will have the next view controller pushed on top of it) you need to set the backBarButtonItem like so:
/**
* Notifies the view controller that its view was added to a view hierarchy.
*
* #param animated If YES, the view was added to the window using an animation.
*/
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
self.title = #"My Title Can Be Long";
self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"ThisIsLimit"
style:UIBarButtonItemStylePlain
target:nil
action:nil];
}
Now, when the next view controller is pushed on top of it, the back button will be whatever title you put in the backBarButtonItem.

Due to low reputation I cannot add a comment so I'm posting an answer while this is not actually an answer.
But,
self.navigationController.navigationBar.topItem.title = #"";
which is written in one of the answers, is equivalent to:
self.title = #"";

try this,
self.navigationController.navigationBar.topItem.title = #"";

iOS 7 will automatically replace your back button title with "Back" or even remove the title altogether in order to fit the title of current navigation item. You probably shouldn't try to do anything about it except maybe try and make your titles shorter.
if you want to make short title you can do as below
self.title = #"SOME REALLY LONG NAVIGATION BAR TITLE";
UILabel* label=[[UILabel alloc] initWithFrame:CGRectMake(0,0, 200, 40)];
label.text=self.navigationItem.title;
label.adjustsFontSizeToFitWidth=YES;
self.navigationItem.titleView=label;

Related

How to hide back button title on iOS7 with NavigationController

I have a NavigationController based iOS7 app , on this I want to hide the back button text which is displayed along with the chevron. Is there a way out to this ? I tried setting empty string to the back button title , tried empty title on previous view as well seems like if it finds empty title it replaces that with "Back" text.
Please help
Thanks
Finally ended up solving it as follows , this one worked perfect.
self.navigationController.navigationBar.topItem.title = #"";
from this link Removing the title text of an iOS UIBarButtonItem
But if you navigate from previous view to next view you can see that the title of the previous view navigation bar vanishes when i put the above mentioned solution in viewDidDisappear of viewWillDisappear of previous view, which isn't an elegant solution in storyboard based UINavigationController scenario , in another situation i finally decided to use a bar button and set its image as per the native back button chevron, this gives better results.
The answer proposed by #vishal has a serious drawback: it removes the title from controller A if you navigate back from A to B.
Here is a safer solution to apply on controller A before pushing controller B:
self.navigationController.navigationBar.topItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:#"" style:UIBarButtonItemStylePlain target:nil action:nil];
And for swift:
if let topItem = controller.navigationController?.navigationBar.topItem {
topItem.backBarButtonItem = UIBarButtonItem(title: "", style: UIBarButtonItemStyle.Plain, target: nil, action: nil)
}
If you want to hide back button title into all your app, put this in you App Delegate:
#implementation UINavigationItem (myCustomization)
-(UIBarButtonItem *)backBarButtonItem
{
return [[UIBarButtonItem alloc] initWithTitle:#"" style:UIBarButtonItemStyleBordered target:nil action:nil];
}
#end
tested on iOS 7
For hide the back button of navigation controller ,try this one:
[self.navigationItem setHidesBackButton:YES animated:YES];
[self.navigationItem setBackBarButtonItem:nil];
[self.navigationItem setLeftBarButtonItem:nil animated:NO];
may it will help you.
happy coding...:)
The simplest solution is to remove the back button title with
navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .Plain, target: nil, action: nil)
in viewWillAppear on the presenting view controller. Note, presenting not presented.
From Removing the title text of an iOS UIBarButtonItem.

Adding BarButtonItems to backButton in view controller

i have a view controller, which is standalone and has two left UIBarButtonItem, however when i push it, i want to have these two buttons + the back button
i tried
- (void)viewDidLoad
{
[super viewDidLoad];
// back
if (self.navigationController.navigationItem.backBarButtonItem) {
self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:self.navigationController.navigationItem.backBarButtonItem, self.barButtonFilter, self.barButtonFilterContacts, nil];
} else {
self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:self.barButtonFilter, self.barButtonFilterContacts, nil];
}
}
if there is a back button, than add, else replace
but i didnt work
I am not able to get your problem but according to your caption you want to replace you back button of UINavigationController with a bar button item, in that case you simply need to have a custom button in place of back Button:
UIBarButtonItem *backButton= [[UIBarButtonItem alloc] initWithTitle:#"yourTitle" style:UIBarButtonItemStylePlain target:self action:#selector(someFunction:)];
self.navigationItem.rightBarButtonItem = backButton;
[backButtonrelease];
If this is not your problem please elaborate.
So the issue here is that a UINavigationBar can only have one leftButtonItem and one rightButtonItem. But What you can do is in the center of the UINavigationBar you can have a UIView. You can use this to place the buttons on.
Someone has the code here: adding-buttons-to-the-titleview-of-navigationbar-without-having-to-repeat-code
From Apple's iOS Human Interface Guidelines:
Use a toolbar instead of a navigation bar if you need to offer a
larger set of controls, or you do not need to enable navigation.
Avoid crowding a navigation bar with additional controls, even if
there appears to be enough space. The navigation bar should contain no
more than a view’s current title, the back button, and one control
that manages the view’s contents. If, instead, you use a segmented
control in the navigation bar, the bar should not display a title and
it should not contain any controls other than the segmented control.
http://developer.apple.com/library/ios/#documentation/userexperience/conceptual/mobilehig/UIElementGuidelines/UIElementGuidelines.html

Setting title of UINavigationBar

I have an application which uses a main story board to include a Navigation Controller where the main view is a Table View using a prototype cell content. Each cell in the table view pushes onto a new view which I have created with it's own set of .h .m and .xib files.
The table view navigation bar has its title set through the story board which works fine. However, I am having trouble setting the title for each new view after it gets pushed into view.
I have the following in the viewDidLoad method for each view;
self.title = #"View Title";
Any advice?
it is the right way. it will work.
I'm doing something similar in an app I'm working on. Here's how I'm setting the title:
[[self navigationItem] setTitle:#"My View's Title"];
I thinkt the dot notation equivalent would be something like this:
self.navigationItem.title = #"My View's Title";
Hope that helps.
If you have a tab bar controller, try this:
self.tabBarController.navigationItem.title = #"Title";

How to refresh navbar so that latest title is displayed?

In my implementation, I will change the title of the page after triggering some method
//In viewdidload of my view controller which resides in a navigation controller
-(void)viewDidLoad
{
self.title = #"Title A";
}
-(void)changeTitle
{
self.title = #"Title B";
}
In the above example, after I trigger the 'changeTitle' method, I do not see my viewcontroller's title change immediately. In fact I need to push another viewcontroller onto the stack and subsequently press 'back' before I see the change to "title B".
Is there any way to refresh the navbar's title at the point where I change title?
I guess you are looking for:
UrNavController.navigationBar.topItem.title = #"bkjasdkahsdflkjadf";
You can reset it after you press a button.
You may also assign some other objects to that topitem like a segmentcontrol, or uilabel.
If you want to refresh the previous viewController's title then use
self.parent?.title = "Some Title"
Objective-C
[self.navigationItem setTitle:#"XYZ"];
Swift 4.2
self.navigationItem.title = "XYZ"

UIView transitions present modal view at the bottom

I need to display a UIView/UIViewController when the user taps a button and the modal view should appear just like how the key board appears from the bottom bar when you edit text in a UITextField. Using the following code, I get to show it as a pop up.
[self presentModalViewController:child animated:YES];
How to make it appear like the keyboard?
I understad modal views cover the entire screen. But I really want a view that covers only half the screen. So, please tell me why this doesn't work
MyController *controller = [[MyController alloc] initWithNibName:#"MyView" bundle:nil];
CGRect frame = CGRectMake(0,44,768,264);
[controller view].frame = frame;
contoller.delegate = self;
[[self view] addSubView:[controller view]];
[controller release];
I am trying to add a sub view to my current view and make it appear where the keyboard appears.
Check if your child.modalTransitionStyle == UIModalTransitionStyleCoverVertical.
(And a model view controller always cover the whole screen. If you just need to cover half of the screen like the keyboard, you need to put the view controller's view as a subview of the main view, then animate it in manually with animation blocks.)
I know its an old question, but an answer to this is to use a UIActionSheet.
It won't present a View Controller, but you can present custom views that only cover a portion of the screen.
Check out this question for more information
Add UIPickerView & a Button in Action sheet - How?