This comes up on Stack Overflow often enough that it seems worth a little article here. The issue is this: You set the frame
of a view or layer in code, but it doesn’t seem to come out in the right place. The reason is usually that you’re doing this too soon.
View Controllers
The dreaded double-segue mistake
This turns out to be a surprisingly common mistake with table views and collection views:
-
In the storyboard, you connect a segue from the cell prototype to another view controller.
-
In code, you implement the delegate method
didSelectRowAt
ordidSelectItemAt
to callperformSegue
to trigger the segue.
The result of this mistake is that when the user taps the cell, the segue is triggered twice.
Don’t touch my outlets
Outlets (@IBOutlet
) are view controller properties that point to views in the storyboard, such as UILabels, UITextFields, and so forth. Outlets are wonderful things, but you should consider them private. Only the view controller that declares an outlet should touch the outlet. Everyone else: hands off.
Don’t make a new view controller by mistake, part 2
As I said in my previous post, there’s a common mistake where a programmer creates a new view controller instance when that isn’t what’s really intended.
Continue readingDon’t make a new view controller by mistake!
One of the most common mistakes I see iOS programming beginners make on Stack Overflow is creating an instance when they intend to refer to an instance that already exists.
Continue reading