Making your iPad app redraw a UITableView

Reading time ~1 minute

Apple HATES redrawing views.  They are so brutal they kill cells in a tableview when the leave the view.  That’s just mean. I mean a cell can’t take up that much memory can it?  There are a bunch of fun methods you can use to try and redraw a view in Cocoa Touch.  You can call

[self.view setNeedsDisplay];

[self.view setNeedsLayout];

or if you’re trying to reload a UITableView you can call

[yourTableView reloadData];

The problem with that method is that it only works on the table’s datasource.  If you want to actually redraw the table you’ll need to be a bit more creative.

The app I’m currently working on has two different views based on whether or not you’re in the landscape or portrait orientation.  We noticed a bunch of bugs that dealt with pushing/popping views on the stack in one orientation then changing orientation and navigating back.  The views always looked shitty until you changed orientation.

Here’s a little trick to force a reload.

Implement the viewWillAppear method in your view controller like so.  And from that method call your willRotateToInterfaceOrientation passing in your current UIDevice orientation.

- (void) viewWillAppear:(BOOL)animated
 [super viewWillAppear:animated];
 int orientation = [[UIDevice currentDevice] orientation];
 if(orientation != UIDeviceOrientationUnknown)
   [self willRotateToInterfaceOrientation:orientation duration:0];

This will force a redraw right before the view loads and will present your nice, shiny UI to your users.

Writing Node.js Apps from Scratch

Satirical posts regarding the bloat of modern day apps are a hot topic of both memes and [dev discussion boards](… Continue reading

Servicing Your Actual Customer

Published on May 26, 2016

Testing your APIs with Cucumber

Published on August 02, 2015