I don't know exactly what's the right place to set things like the tintColor of the NavigationBar or the title of my ViewController. It works in the -init method and the -viewLoad method too. What is the "best-practice" or "right way" to do this? Has one of those any advantages?
相关问题
- Core Data lightweight migration crashes after App
- How can I implement password recovery in an iPhone
- State preservation and restoration strategies with
- “Zero out” sensitive String data in Swift
- Get the NSRange for the visible text after scroll
相关文章
- 现在使用swift开发ios应用好还是swift?
- UITableView dragging distance with UIRefreshContro
- TCC __TCCAccessRequest_block_invoke
- Where does a host app handle NSExtensionContext#co
- Swift - hide pickerView after value selected
- How do you detect key up / key down events from a
- didBeginContact:(SKPhysicsContact *)contact not in
- Attempt to present UIAlertController on View Contr
The right place is to set it in
viewDidLoad
. To know more about those methods, apple has provided the documentationThe
init
methods (yes there is more then one) are where theUIViewController
is initialized. Thus this is the place where you do stuff for theUIViewController
and not its views.If you use a
nib
to load you view then the best place to set any properties is theviewDidLoad
method. This method gets called after thenib
is loaded. If you set up the view programatically use theloadView
method then this is the place to setUIControl
properties.Since the system can unload views to save memory, it will leave the
UIViewController
alone. Any properties set in theinit
methode will not be applied again, since theUIViewController
is already initialized.the init method is used to initialize the viewController while viewDidLoad method is used to load your nib(i.e. your view). so when you want to do something with your viewController then use init method and when you want to do something with your view then use viewDidLoad.