John John - 3 years ago 185
Swift Question

Navigation Left bar button item with back button

I want to add left bar button item in

I have back button sign (do not have any text) in left side and when I add
then I can not see the back button.

How can I solve this problem.

This is my code:

let phonePhoto = UIButton()
phonePhoto.setImage(UIImage(named: "navigationPhone"), for: UIControlState())
phonePhoto.frame = CGRect(x: 0, y: 0, width: 40, height: 40)
phonePhoto.addTarget(self, action: #selector(userEdit), for: .touchUpInside)

let userPhone = UIBarButtonItem()
userPhone.customView = phonePhoto

self.navigationItem.leftBarButtonItem = userPhone

Answer Source

The presence of custom left bar button items causes the back button to be removed in favor of the custom items. Set navigationItem property leftItemsSupplementBackButton to true will display back button also with your custom left bar item.

self.navigationItem.leftItemsSupplementBackButton = true

Check Apple Documentation on leftItemsSupplementBackButton for more details.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download