0

So I have a subview called emptifier in a TableViewController that is just an empty UIView and an empty sub-subview. I use emptifier to hide the separator for the last cell in my tableview. But when I have an empty table, I want to push this subview to the back of the tableview hierarchy (behind all the other cells) so that I can actually see the separators and see that the tableview is empty.

So here is what I have in code:

    func clearTable() {

         /*
         Clearing table code
         */

         //To show the last cell's separator:
         self.emptifier.superview!.sendSubviewToBack(self.emptifier)
    }

And:

    func loadTableResults() {

         /*
         Load Results code
         */


         //To hide the last cell's separator:
         self.emptifier.superview!.bringSubviewToFront(self.emptifier)
    }

Now this should work perfectly, and I checked using print(tablview.subviews) that emptifier is a subview of the table AND that it moves to the front/back of the table correctly. But for some reason, whatever order I set in the storyboard beforehand reins supreme, it's as if I don't have anything written in code.

My guess is that there is something having to do with tableviewcontrollers that I just don't understand and I just can't manipulate a tableview's subviews that way. But I tried to look it up and I couldn't find anything.

JoeVictor
  • 1,806
  • 1
  • 17
  • 38
  • "I use emptifier to hide the separator for the last cell in my tableview" It would be better to manage the separators in the way that table views intend for you to do. Adding extra subviews to a table view is skanky and unsupported. – matt Jun 12 '16 at 01:27
  • This isn't as "skanky and unsupported" as you think. The subview just covers the separator by being in front of it. This isn't some hidden API or something that I'm not allowed to use. – JoeVictor Jun 12 '16 at 17:49
  • Whatever. I repeat, the table view gives you built-in ways to manage the separator, and _your_ way is not working, so you might be better off using the "real" ways, no? If you don't want suggestions, what's the question for? — By the way, you should be using View Debugging to see where your view is actually ending up. You might be surprised by what you learn. – matt Jun 12 '16 at 18:06
  • Ok, I'd love suggestions, can you please tell me how I would do this the "real" way? I posted a [previous question](http://stackoverflow.com/questions/37766614/how-do-i-get-the-default-cell-separator-color-also-how-do-i-set-separator-colo/37766672?noredirect=1#comment63002947_37766672) about this problem and this way was the only useful answer. – JoeVictor Jun 12 '16 at 18:08
  • I don't agree. I think http://stackoverflow.com/a/37767092/341994 is an excellent suggestion. It is trivial to draw the separators yourself and escape entirely from the tyranny of the built-in separators, which do all sorts of things I don't like. – matt Jun 12 '16 at 18:11
  • Well yeah, but then _that_ leads me to build separators myself, which is not the "apple" way to do it. Which means that I have no idea how this can act in future iOS releases. Which can do all sorts of things _I_ don't like – JoeVictor Jun 12 '16 at 18:13
  • You have it backwards. What _you_ are doing is not the apple way. Getting rid of the separators _is_ Apple-legal and always will be, and you are then free to draw the separator as part of the cell background — and now you can do different things for different cells, just as you desire. See my screen shot on this answer, for example: http://stackoverflow.com/a/22694298/341994 – matt Jun 12 '16 at 18:15
  • I think my main issue is that I know there's a way to do this without making my own separators. A reddit iOS client called narwhal does this, and I'm fairly certain they don't use their own separators. So I want to find out how they do it. Don't get me wrong, your way has it's uses I just feel it's way too much of a hassle to remove _all_ the separators just for a single cells. – JoeVictor Jun 12 '16 at 18:24

0 Answers0