looking for some solutions? You are welcome.

SOLVED: xcode navigation bar button state

Vahag Chakhoyan:

I have an edit button - UIBarButtonItem

enter image description here

which disappears from screen when it was clicked

enter image description here

and appears when cancel button was clicked

enter image description here

As you can see, the state of edit button stays selected after appearing. How can I programmatically change Navigation bar buttons state to normal state?

here is my project code

class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource, introductionDelegate {

var navBarEditButton: UIBarButtonItem?
var navBarDeleteButton: UIBarButtonItem?
var navBarCancelButton: UIBarButtonItem?

override func viewDidLoad() {
    super.viewDidLoad()
    self.navBarEditButton = UIBarButtonItem(title: "Edit", style: .plain, target: self, action: #selector(editObjectsAction))
    self.navBarDeleteButton = UIBarButtonItem(title: "Delete", style: .plain, target: self, action: #selector(deleteObjectsAction))
    self.navBarCancelButton = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(cancelAction))

    self.navigationItem.leftBarButtonItems = [navBarEditButton!]
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

@objc private func editObjectsAction(_ sender: UIBarButtonItem) {
    self.navigationItem.leftBarButtonItems = [navBarCancelButton!, navBarDeleteButton!]
}

@objc private func cancelAction(_ sender: UIBarButtonItem) {
    self.navigationItem.leftBarButtonItems = [navBarEditButton!]
}

@objc private func deleteObjectsAction(_ sender: UIBarButtonItem) {

}



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
Share:

No comments:

Recent