I am creating a NavigationBar with UIBarButtonItem which located on right side of screen. As default I set that setRightBarButton with UIBarButtonItem(image: UIImage(named: "edit"), style: .plain, target: self, action: #selector(editProfile)) and when I clicked on that it should change that rightBarButton to other title but it doesn't work.
Here is I tried to change with I clicked on it
@objc
func editProfile() {
self.navigationItem.setRightBarButton(cancelActionBar, animated: true)
}
This is object of cancelActionBar
let cancelActionBar = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(cancelEdit))
And this is its action which change it back to default.
@objc
func cancelEdit() {
self.navigationItem.setRightBarButton(editActionBar, animated: true)
}
I also tried to use main thread as well but it is not working as I expected.
editProfilecalled?viewdidload(). Now it is working