Category Archives: gotchas

Memory Warnings

This post gives a quick intro to dealing with memory warnings in iOS. I have to admit, I’ve avoided this subject for a looong time while learning iOS.  The first word says “these bugs will be incredibly annoying” and the second word says “you can just ignore these.”  Or rather, that’s what the back of […]

Handling rotations in UIViewController

In this post I’ll give a few general tips for handling device rotations at the UIViewController level.  These tips are for code using iOS (formerly known as iPhone OS) 3.0 or later, which includes all iPad code. 1.  In willAnimateRotationToInterfaceOrientation:duration:, size and position the view for the new orientation. This sounds obvious and easy, but there […]

Clash-happy method names

This post lists a few special-case method names that are somewhat likely to be used accidentally by you but can only be used correctly if you understand their built-in functions.  Specifically: class, description, load, and hash. Why it’s tricky, by example Here’s an easy way to mess this up: start with a model object meant […]

Hacking the responder chain

This post could have also been called “How to allow user interaction with views beneath other views,” but that title is a little too long. I’m going to assume you have at least some idea of what the responder chain is for this post. (There’s an example xcode project below for those who like to […]

Custom objects as NSDictionary keys

This post describes what is needed for any class to work as a key of NSDictionary or NSMutableDictionary. The only thing that is really required is that your class adopt the NSCopying protocol.  That’s because every key is copied before being added to the dictionary.  I mention why this design decision was probably made below. […]

Event tracking stops NSTimer

NSTimers usually don’t fire when the user is scrolling a table or other UIScrollView – or doing anything else that puts the run loop in event tracking mode.  This post describes the problem and an easy solution. The problem Suppose you set up a timer in the most convenient manner, with something like this: [NSTimer […]

Detecting orientation

I was surprised to learn today that [[UIDevice currentDevice] orientation] doesn’t always give the correct orientation. In fact, it seems to consistently fail whenever it’s called early in the app launching process. What’s up with that? What’s going wrong If you command-double click on UIDeviceOrientation, you’ll see that this type is an enum defined in […]