Search code examples
swiftuitableviewuinavigationcontrolleruistoryboarduinavigationitem

Show navigationItem in UITtableView


I created one File it's Swift I add class Mypage: UITableViewController, After in Storyboard I add one New UITableviewController and add Class and in Editor Storyboard -> Embed in I add UInavigateController

now I use to going to this tableviewcontroller

let viewController:UITableViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Mypage") as! UITableViewController

self.present(viewController, animated: false, completion: nil)

when I go to Mypage I don't See navigator and I don't see the Rightbutton

    override func viewDidLoad() {

        super.viewDidLoad()

        tableView.tableFooterView = UIView()


        self.navigationItem.rightBarButtonItem = self.editButtonItem

}

I need to see right bar button


Solution

  • There are two ways:

    1. Present "Mypage" with UINavigationController and Mypage as rootViewController

      let viewController:UITableViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "Mypage") as! UITableViewController
      
      let navigationContoller = UINavigationController(rootViewController: viewController)
      self.present(navigationContoller, animated: false, completion: nil)
      
    2. Perform seque from button to the navigation controller on Storyboard. (Use control-drag on Button) enter image description here]