iosxcodeuitableviewxcode9.2

UITableViewCell's contents disappear when app run in simulator


UITableViewCell shows up in Main.storyboard but doesn't show up in simulator.

I'm using Main.storyboard. In my simple experiment with Swift, I added a TableView, then put a UITableViewCell in it, and then I put an image and a label under the cell's content. It looks okay in Main.storyboard but when I run the project, the content disappear. All I did is purely on Main.storyboard and not touching the .swift file yet.

Here are the links of screenshots of my simple work:

I have searched the problem through the stackoverflow and found a related question here: 'UIImageView doesn't show up in simulator', then I followed the recommended solutions from the forum but still didn't solve the bug.

What I have done so far to solve the bug:

  1. Check if every item in my view has four constraints defining X, Y position, width and height.
  2. Try to check and uncheck the autolayout flag for my Main.storyboard
  3. Make sure my tableview cell's contents (and everything inside my view) has alpha set to 1

Well I haven't check how things looks in my .xib file. I would like to know if this is a bug, or just a problem in my settings?

I'm quite new to Xcode, swift, and iOS app. Any help or suggestion would be greatly appreciated. If you have the same problem with me, I would like to know your case as well.


Solution

  • The only reason your cell doesn't show up in the simulator is because your tableview is dynamic.

    Dynamic table views have data that is loaded at runtime, where there isn't a fixed number of cells, and every cell has the same layout. The Apple tutorial is a good place to start. It guides you through on how to use a tableview/tableviewcontroller.

    There is no way around it: You have to code in .swift files if you want to use dynamic table views.

    If you are going to use static table views, on the other hand, the number of cells is fixed, and the data is not loaded at runtime. You can use static tableviews if you don't want anything to do with code at the moment.