It always occurs when you are using the table view controller in your iOS Xcode project & when you navigate from the table view cell to the detail view of your app in the storyboard on the iOS Simulator or the actual device, the ‘Back,’ button Appears at the top left. What if you want to add a button beside the ‘Back’ button, And you want to know how? Here is the solution,
You have to add the following code in your ‘viewdidLoad’ function in your desired ViewController.m file:
self.navigationItem.leftItemsSupplementBackButton = YES;And supplement above code with the following code to call button:
let share = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: #selector(shareAction))
if let leftItems = self.navigationItem.leftBarButtonItems {
self.navigationItem.leftBarButtonItems = leftItems + [share]
} else {
self.navigationItem.leftBarButtonItems = [share]
}
Now your viewDidLoad function should look like this:
override func viewDidLoad() {
super.viewDidLoad()
print("viewDidLoad")
// Do any additional setup after loading the view.
navigationItem.leftItemsSupplementBackButton = true
let share = UIBarButtonItem(
barButtonSystemItem: .action, target: self, action: #selector(shareAction))
if let leftItems = navigationItem.leftBarButtonItems {
navigationItem.leftBarButtonItems = leftItems + [share]
} else {
navigationItem.leftBarButtonItems = [share]
}
}
Hope it helps,
Thanks & Regards
Mandar Apte





Leave a Reply