методы просмотра iPhone - PullRequest
0 голосов
/ 08 марта 2011

Скажите, пожалуйста, шаг за шагом различные методы просмотра iOS.Пожалуйста, объясните, какой метод выполняется первым и т. Д. Я хочу сказать, какой метод был выполнен, когда?

Ответы [ 2 ]

3 голосов
/ 08 марта 2011
  1. Init или InitWithCode или InitWithNibName или (любой метод инициализации)
  2. loadView /// он вызывается только тогда, когда у вас есть собственный viewController и вы загружаете пользовательское представление вместо этого из nibFile, обычно loadView не вызывается
  3. viewDidLoad
  4. viewWillAppear
  5. viewDidAppear

на стороне выгрузки

  1. viewWillDisappear
  2. viewDidDisappear
  3. viewDidUnload
  4. dealloc

Они относятся только к viewController, но не для tableView или другого типа viewController.Если я пропустил какой-либо метод, пожалуйста, добавьте комментарии.

0 голосов
/ 08 марта 2011

Для вашего конкретного вопроса вы должны добавить подпредставление в viewDidLoad. Потому что, если вы перезаписывает loadView, вы должны выполнять все задания, загружая все представления.

Вот объяснение из документации Apple:

Шаги, которые происходят во время цикла загрузки, следующие:

1.

  * Some part of your application asks for the view in the view

controller’s view property.

2.

  * If the view is not currently in memory, the view controller calls its loadView

method.

3.

  * The loadView method does one of the following:

        If you override this method, your implementation is

responsible for creating all necessary views and assigning a non-nil value to the view property.

        If you do not override this method, the default implementation uses 

the nibName and nibBundle properties of the view controller to try to load the view from the specified nib file. If the specified nib file is not found, it looks for a nib file whose name matches the name of the view controller class and loads that file.

        If no nib file is available, the method creates an empty UIView object 

and assigns it to the view property.

4.

  * The view controller calls its viewDidLoad method to perform any

additional load-time tasks.
...