سؤال

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top