iosswiftuitableviewrightbarbuttonitem

How do I incorporate an add text box to the navigationItem -> rightBarButtonItem?


I want to incorporate an add text box to my rightBarButtonItem so that the user is prompted for a title name when clicking on the rightBarButtonItem. This is for the TableViewController class in order to add new cell names. So far all my code does is add new cells with no custom names.

Here's my code so far:

override func viewDidLoad() {
    super.viewDidLoad()

self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "generate new item", style: .plain, target: self, action: #selector(TableViewController.insert))

}

Solution

  • If you are using default navigation bar, I mean in your app default navigation bar shown, then first hide navigation bar. And create your own navigation bar with UIView with same height of navigation bar (i.e 64) and add UITextField to that view.

    This is only option you can add text field to navigation bar.