Search code examples
iosswiftxcode-storyboard

Swift - UITableViewController and Storyboard not linked


enter image description here

I am adding a UITableViewController and created it programatically for a reason. I also assigned this custom controller to my storyboard. However, when I run it, it doesn't seem like they are linked because I don't see the cell header ("Suggestion" in the screenshot below). If I set this controller to an initial controller, I can see it thou. Having this said, it is something to do with creating my controller programatically? Please advice me what is missing..

enter image description here

UPDATE: It is actually a part of creating a UISearchController. Here is my code snippet.

    searchResultController = CustSearchGoogleResultTableViewController()
    let searchController = UISearchController(searchResultsController: searchResultController)

Solution

  • Simply creating an instance of a view controller as you are won't get any of the details that you have configured in the storyboard.

    You need to use instantiateViewControllerWithIdentifier and to do this you need to put an identifier into the storyboard scene - on the right of your screen shot where it says "Storyboard ID", say 'searchController'. Once you have done that you can use

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    let searchResultController = storyboard.instantiateViewControllerWithIdentifier("searchController") as! CustSearchGoogleResultTableViewController
    let searchController = UISearchController(searchResultsController: searchResultController)