skip to Main Content

I am trying to add a UITableView element to a XIB which I want to present as a sheet from the bottom but I only get the option of static cells. Isn’t it possible to have dynamic tables within a XIB or am I missing something?

https://i.stack.imgur.com/1tTkl.png

Usually Content Field is visible and I select 1 prototype cell for simple use cases

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    I have managed to achieve my goal using matt's answer via creating a Storyboard and assign it to my custom UIViewController class.

    enter image description here

    Make sure to set the Class and Storyboard ID:

    enter image description here

    The code to present and use the Storyboard from the the presenting ViewController:

    let popup = UIStoryboard(name: "MyPopupVC", bundle: nil).instantiateViewController(withIdentifier: "myPopupUniqueID") as! MyPopupVC
    
    if let sheet = popup.sheetPresentationController {
    sheet.detents = [.large()]
    sheet.prefersGrabberVisible = true
    }
    popup.set(account: account) //Transfer account object to popup VC
    present(popup, animated: true)
    

  2. A prototype cell is a feature of a table view controller, not a table view. You would need to have a table view controller object in your XIB in order to have a prototype cell. Having a table view controller in a XIB is a perfectly legal thing to do, though it is rarely done nowadays, because storyboards are generally easier to work with and are more powerful.

    I don’t recommend putting a table view controller in a XIB just in order to get a prototype cell. Keep in mind that there are also two other ways of having the runtime instantiate a cell for you when you dequeue:

    • Register a XIB file that contains just a cell object.

    • Or, register a cell type that is a UITableViewCell subclass.

    Or just use a storyboard if you really want a prototype cell. A storyboard containing nothing but a single table view controller scene is perfectly legal and viable.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search