At the beginning

  • This is a sub-chapter. For the whole article, see the Learning Diary of Zero-based iOS development

Interface jump -modal

  • In modal mode, there is no connection between the forward and backward jump interface
  • UINavigationControllerSee the jumpCustomize the root controller and UINavigationController
  • jump
- (void)btnClick { testViewController *vc = [testViewController new]; / / full screen pops up vc. ModalPresentationStyle = UIModalPresentationFullScreen; [self presentViewController:vc animated:YES completion:nil]; }Copy the code
  • disappear
- (void)back {
    [self dismissViewControllerAnimated:NO completion:nil];
}
Copy the code

View life cycle

System correlation function

  • Create a view, so the view is nil at first, so if you want to customize the view, you don’t have to call itsuperThe method of
// load - (void)loadView {[super loadView]; NSLog(@"ViewController - loadView"); }Copy the code
  • The control is loaded, but is not displayed and is not added to the interface
- (void)viewDidLoad {[super viewDidLoad]; NSLog(@"ViewController - viewDidLoad"); }Copy the code
  • That’s when you start adding child controls, that’s when you display them, that’s when you have a view hierarchy, and that’s when you end up with the interface
// will appear - (void)viewWillAppear:(BOOL)animated {[super viewWillAppear:animated]; NSLog(@"ViewController - viewWillAppear"); }Copy the code
  • Full appearance of interface
- (void)viewDidAppear:(BOOL)animated {[super viewDidAppear:animated]; NSLog(@"ViewController - viewDidAppear"); } / / will disappear - (void) viewWillDisappear: (BOOL) animated {[super viewWillDisappear: animated]; NSLog(@"ViewController - viewWillDisappear"); } / / has disappeared - (void) viewDidDisappear: (BOOL) animated {[super viewDidDisappear: animated]; NSLog(@"ViewController - viewDidDisappear"); }Copy the code

The order in which the interface appears

ViewController - loadView
ViewController - viewDidLoad
ViewController - viewWillAppear
ViewController - viewDidAppear
Copy the code

Interface switching sequence

testViewController - loadView
testViewController - viewDidLoad
ViewController - viewWillDisappear
testViewController - viewWillAppear
testViewController - viewDidAppear
ViewController - viewDidDisappear
Copy the code

The order in which the interface jumps back

testViewController - viewWillDisappear ViewController - viewWillAppear ViewController - viewDidAppear testViewController  - viewDidDisappear testViewController - deallocCopy the code

The actual use

  • In my actual development, the most frequent operation is still inloadViewandviewDidLoad
  • loadViewIt’s in the controllerThe view is nilThat is, when you need to change the root view of your controller, you can write it in this function, and you don’t need to call the super method
  • So, control loading is usually written inviewDidLoadIn the

conclusion

  1. Interface hopping is like stacking plates one by one. The bottom ones are kept forever, and when the top ones are removed, they are destroyed
  2. In the whole interface display process, data loading and display, in fact, is separate