简体   繁体   中英

UITableViewController doesn't show content when embedded in a Container in another UIView

What I basically did was that I embedded a UITableViewController into a container in another UIView. Background is, that in a normal TableView, I would not be able to set static cells and load icons in the lines individually for each cell. I followed these steps which I found online:

  1. Drag a ViewController onto your storyboard.
  2. Drag a TableViewController onto your storyboard.
  3. Next Drag a Container view to your ViewController and size it about the size you want (smaller than the view) -> when you drag the container view it will create a segue and another view. Remove that segue and view.
  4. Finally ctrl click in your container and drag to your new TableViewContoller. Select Embed.

My result looks like this:

Screenshot from xcode

The problem is now, that my Container doesn't show the content. It shows that it is a table, but basically an empty one and not the little icons or textfields which should be there. See here:

Screenshot from Simulator

Do you guys have any suggestions what I did wrong or what can I do to show the content? If you need more information please comment. Thx for your help!

Matt

Okay I found the solution. I basically took out the tableViews datasource in EditProfileContainerTableViewController. This was the code which made the problems:

        // MARK: - Table view data source

//    override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
//        // #warning Incomplete implementation, return the number of sections
//        return 1
//    }
//
//    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
//        // #warning Incomplete implementation, return the number of rows
//        return 5
//    }

I added an screenshot for you guys, if anybody has a similar problem he can contact me. I'm happy to help :)

EditProfileContainerTableViewController

1)It might be happening because your delegate will be tableViewController not View controller. 2)So instead of adding tableViewController add TableView in ViewController & write delegate & datasource methods in ViewController

You're right. Basically you can't have static cells and keep the TableView datasource section (ie by default the number of sections and number of rows per section function). When the controller loads, it will recreate dynamic cells according to these functions thus hiding your static cells

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM