0

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.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
Daniel Kurniadi
  • 178
  • 2
  • 13
  • You forgot to set dataSource and delegate for tableView I guess. – Tushar Sharma Jan 07 '18 at 16:34
  • @DanielKurniadi Is your tableview static or dynamic? – Xcoder Jan 07 '18 at 16:36
  • Show your code from the `ViewController.swift` file – nayem Jan 07 '18 at 16:39
  • @nayem OP said that he didn't even touch the .swift file... – Xcoder Jan 07 '18 at 16:40
  • Oh well! @Xcoder. I didn't notice that. As a beginner, you should try some tutorial. [Here](https://stackoverflow.com/a/36426858/3687801) is a good one for custom UITableViewCell. Follow that, you will get to know how they work. __It is very hard to explain everything that you will need to follow from the very beginning. So it's wise to follow some previous guidelines__ – nayem Jan 07 '18 at 16:47
  • @DanielKurniadi Check out my answer, and let me know if it works for you. – Xcoder Jan 07 '18 at 22:46
  • @nayem I haven't done any code yet XD.. I was trying to check if my auto-layouts are good before I proceed to coding parts. Thanks for the advice! I will learn more from more tutorials. Thanks guys! – Daniel Kurniadi Jan 08 '18 at 09:38

2 Answers2

1

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.

Xcoder
  • 1,433
  • 3
  • 17
  • 37
-1

I had a similar problem. I solved it by deleting constraints for the affected view and starting all over.

Saad
  • 1
  • 1