Creating a View Controller Using Nib Files
initWithNibName:bundle:
Returns a newly initialized view controller with the nib file in the specified bundle.
从指定的bundle中通过nib文件得到新的初始化的视图控制器
Parameters
-
nibName
-
The name of the nib file to associate with the view controller. The nib file name should not contain any leading path information. If you specify
nil
, thenibName
property is set tonil
. -
nibBundle
-
The bundle in which to search for the nib file. This method looks for the nib file in the bundle's language-specific project directories first, followed by the
Resources
directory. If this parameter isnil
, the method uses the heuristics described below to locate the nib file. -
-
参数
-
nibName
-
和视图控制器相关的nib文件的名字。nib文件不应该包含任何主要的路径信息。如果你指定为nil,那么 nibName属性被设置为nil.
-
nibBundle
-
系统将在这个bundle中寻找nib文件。这个方法首先在bundle指定语音的项目目录中寻找 bundle文件。然后在Resources目录找。如果这个参数为nil,那它会用下面说明的启发式算法锁定nib文件
-
-
Return Value
A newly initialized UIViewController
object.
Discussion
This is the designated initializer for this class.
The nib file you specify is not loaded right away. It is loaded the first time the view controller’s view is accessed. If you want to perform additional initialization after the nib file is loaded, override the viewDidLoad
method and perform your tasks there.
If you specify nil
for the nibName parameter and you do not override the loadView
method, the view controller searches for a nib file using other means. See nibName
.
If your app uses a storyboard to define a view controller and its associated views, your app never initializes objects of that class directly. Instead, view controllers are either instantiated by the storyboard—either automatically by iOS when a segue is triggered or programmatically when your app calls the storyboard object’s instantiateViewControllerWithIdentifier:
method. When instantiating a view controller from a storyboard, iOS initializes the new view controller by calling its initWithCoder:
method instead. iOS automatically sets the nibName
property to a nib file stored inside the storyboard.
For more information about how a view controller loads its view, see “Resource Management in View Controllers”.
nibName
Return the name of the receiver’s nib file, if one was specified. (read-only)
如果指定了一个nib文件,返回接受者的nib文件的名字。(只读)
Discussion
This property contains the value specified at initialization time to the initWithNibName:bundle:
method. The value of this property may be nil
.
If you use a nib file to store your view controller’s view, it is recommended that you specify that nib file explicitly when initializing your view controller. However, if you do not specify a nib name, and do not override the loadView
method in your custom subclass, the view controller searches for a nib file using other means. Specifically, it looks for a nib file with an appropriate name (without the .nib
extension) and loads that nib file whenever its view is requested. Specifically, it looks (in order) for a nib file with one of the following names:
-
If the view controller class name ends with the word “Controller”, as in
MyViewController
, it looks for a nib file whose name matches the class name without the word “Controller”, as inMyView.nib
. -
It looks for a nib file whose name matches the name of the view controller class. For example, if the class name is
MyViewController
, it looks for aMyViewController.nib
file.
Note: Nib names that include a platform-specific identifier such as ~iphone
or ~ipad
are loaded only on a device of the corresponding type. For example, a nib name of MyViewController~ipad.nib
is loaded only on iPad. If your app supports both platform types, you must provide versions of your nib files for each platform.
Handling Memory Warnings
didReceiveMemoryWarning
Sent to the view controller when the app receives a memory warning.
- (void)didReceiveMemoryWarningDiscussion
Your app never calls this method directly. Instead, this method is called when the system determines that the amount of available memory is low.
You can override this method to release any additional memory used by your view controller.
If you do, your implementation of this method must call the
super
implementation at some point.
详细描述:
你的应用永远不要直接调用这个