Month: June 2020

  • iOS – How to remove “Back” text from the back button

    The best solution is to create base classes for UIViewController and UITableViewController and override their init methods. This will allow you to add ViewControllers to the NavigationController programmatically after a rootViewController. If you put this code in the ViewDidLoad method, it will not be called in this case and the next controller will be pushed with a back text.

    BaseViewController in Objective C:

    #import "BaseViewController.h"
    
    @interface BaseViewController ()
    
    @end
    
    @implementation BaseViewController
    
    - (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
     self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
     if (self) {
     self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
     }
     return self;
    }
    
    @end
    

    BaseTableViewController:

    #import "BaseTableViewController.h"
    
    @interface BaseTableViewController ()
    
    @end
    
    @implementation BaseTableViewController
    
    - (instancetype)initWithStyle:(UITableViewStyle)style
    {
     self = [super initWithStyle:style];
     if (self) {
     self.navigationItem.backBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil];
     }
     return self;
    }
    
    @end