0

I have this custom UIViewController. It is not connected to anything storyBoard and want to present on clicking a button

class SeeListsViewController: UIViewController {
   
    var tableView = UITableView()
    override func viewDidLoad() {
        
        super.viewDidLoad()
        self.setUpTableView()
        view.addSubview(tableView)
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
        // Do any additional setup after loading the view.
    }
}

How can i do that. I know the storyBoard way but this one has no identifier and it is all programmatically made

  • 1
    Does this answer your question? [Instantiate and Present a viewController in Swift](https://stackoverflow.com/questions/24035984/instantiate-and-present-a-viewcontroller-in-swift) – El Tomato Jul 16 '21 at 03:26
  • Samo, samo, run a search, run a search... – El Tomato Jul 16 '21 at 03:26

1 Answers1

0

The solution below if you have SeeListsViewController in the storyboard and make sure the storyboard identifier is also SeeListsViewController:

let storyboard = UIStoryboard(name: "<Your storyboard name>", bundle: nil)
let listVC = storyboard.instantiateViewController(withIdentifier: SeeListsViewController.self)
self.present(listVC, animated: true)

A programmatic way to present if you don't have a view controller in the storyboard and all the UI components should be designed programmatically in your viewcontroller

let navVC = UINavigationController(rootViewController: SeeListsViewController())
    navVC.modalPresentationStyle = .fullScreen
    self.present(navVC, animated: true, completion: nil)
Ramesh Boosa
  • 198
  • 8