I’ve been working a lot with junior iOS devs this week, and a common issue keeps coming up. They’ll add a
UIView to the screen but, for whatever reason, it doesn’t display.
This type of problem isn’t in any way difficult to debug, but it does require experience. In an effort to help junior devs out there fill in some of those experiential gaps, I present:
Tips for Debugging UIView in the Blind
Implementing the following (often in combination) can help diagnose the source of common view problems.
- Set a breakpoint. Did it hit?
- Is the view non-
- Is it being added to a superview (
- Is the superview non-
- Does the superview have a
- Is the superview what you think it is (try making it blue)?
- Is it
- Is it under a sibling (use
- Does the superview
- Make the view bigger. Can you see it now?
- Make it a lot bigger. How about now?
- Set its center to the superview’s center.
- Make it bright green.
- Make sure its
- Is the view a subclass? Does a stock
- Are any view classes extended with categories?
- What about in your CocoaPods?
- Do any view controller lifecycle methods (
viewDidLayoutSubviews, etc) mess with the view?
- Does your view controller call
supereveryplace it should (
- Is your view controller contained by another view controller that draws on top of it (for example,
- Does your view controller
- Are there edges in
- Can you try rendering your view controller by itself outside of containment?
- Are you getting any constraint consistency errors in log/term?
- Have you set a width/height (or an intrinsic content size)?
- Have you cleaned your project and rebuilt?
- Have you “Reset Content and Settings…” in the simulator?
- Have you tried on both simulator and a device?
- Have you quit Xcode and started it again?
- Have you shutdown your computer and started again?
- Are you on a beta? Stop that.
Minimum Viable Reproduction
- If you create a fresh project with a fresh view and view controller, does the problem persist?
- If you copy and paste your nibs/storyboards?
- If you copy and paste your classes?