New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
The Life and Times of UIViewController
1. The Life and Times of
UIViewController
Brandon Alexander
Wednesday, September 18, 13
2. Who am I
iOS Developer,Author, Speaker
Email: brandon.alexander@gmail.com
GTalk: brandon.alexander@gmail.com
Twitter/ADN: @balexander
Wednesday, September 18, 13
3. Design Pattern
A general reusable solution to a commonly
occurring problem within a given context in
software design
Wednesday, September 18, 13
16. Creation Tips
• Wait for viewDidLoad for some startup
items
• Don’t reference vc.view before
viewDidLoad is called
• Use -[UIVC isViewLoaded]
• Use UIGestureRecognizer when possible
Wednesday, September 18, 13
17. Interaction
• Respond to user actions
• Delegate/Data Source Methods
• Respond to rotation events
• Respond to application notifications
• Navigate to other view controllers
Wednesday, September 18, 13
19. Rotation Support
• Info.plist shows all supported orientations
• Implement proper methods to support
each orientation in each view controller
Wednesday, September 18, 13
20. Interaction Tips
• Split Data Source methods out to helper
objects
• Keep the focus of the class in mind
Wednesday, September 18, 13
21. Destruction
• Implement dealloc when necessary
• Many existing UIKit classes aren’t ARCified
• Set delegate/dataSource properties to nil
Wednesday, September 18, 13
23. Dismissing Presented
View Controllers
• Multiple Approaches
• Delegation
• Post to the responder chain
• Don’t have a view controller dismiss itself
Wednesday, September 18, 13
24. View Controller
Containment
• KeepsView Controller hierarchy the same
as the view hierarchy
• Helps solve the MassiveView Controller
anti-pattern
Wednesday, September 18, 13
27. Other Containment
Methods
- (BOOL) shouldAutomaticallyForwardAppearanceMethods
- (BOOL) shouldAutomaticallyForwardRotationMethods
Wednesday, September 18, 13
28. iOS 7
• CustomView Controller Transitions
• Different layout paradigms
• -automaticallyAdjustsScrollViewInsets
• UIKit Dynamics
Wednesday, September 18, 13
29. Architecture
• Avoid MassiveView Controllers
• Centralize networking code
• Controllers don’t have to be view
controllers
Wednesday, September 18, 13
30. Other Tricks
• Use nil-target actions in views
• Lazy load in container view controllers
• Don’t bother cleaning up in will(Dis)Appear
Wednesday, September 18, 13
31. Resources
• View Controller Programming Guide
• About Cocoa Auto Layout
• iOS 7 UI Transition Guide
Wednesday, September 18, 13