Springs in Auto Layout: Distribute views evenly, with constraints, in Xcode 5

EDIT Note that in iOS 9 this technique will become unnecessary, because a UIStackView will perform distribution automatically. I’ll add another answer explaining how that works. How to Perform Even Distribution Using Autolayout The simplest way to do this in Interface Builder alone (rather than constructing constraints in code) is to use “spacer” views: Position … Read more

What is a StoryBoard ID and how can I use this?

The storyboard ID is a String field that you can use to create a new ViewController based on that storyboard ViewController. An example use would be from any ViewController: //Maybe make a button that when clicked calls this method – (IBAction)buttonPressed:(id)sender { MyCustomViewController *vc = [self.storyboard instantiateViewControllerWithIdentifier:@”MyViewController”]; [self presentViewController:vc animated:YES completion:nil]; } This will create … Read more

“Unknown class in Interface Builder file” error at runtime

Despite the “Unknown class MyClass in Interface Builder file.” error printed at runtime, this issue has nothing to do with Interface Builder, but rather with the linker, which is not linking a class because no code uses it directly. When the .nib data (compiled from the .xib) is loaded at runtime, MyClass is referenced using … Read more

UIScrollView Scrollable Content Size Ambiguity

Updated Nowadays, Apple realized the problem we solved many years ago (lol_face) and provides Content Layout Guide and Frame Layout Guide as part of the UIScrollView. Therefore you need to go through the following steps: Same as above; For this contentView, set top, bottom, left, and right margins to 0 pinning them to the Content … Read more

Should IBOutlets be strong or weak under ARC?

The current recommended best practice from Apple is for IBOutlets to be strong unless weak is specifically needed to avoid a retain cycle. As Johannes mentioned above, this was commented on in the “Implementing UI Designs in Interface Builder” session from WWDC 2015 where an Apple Engineer said: And the last option I want to … Read more

Xcode – How to fix ‘NSUnknownKeyException’, reason: … this class is not key value coding-compliant for the key X” error?

You may have a bad connection in your xib. I’ve had this error many times. While TechZen’s answer is absolutely right in this case, another common cause is when you change the name of a IBOutlet property in your .h/.m which you’ve already connected up to File’s Owner in the nib. From your nib: Select … Read more