一、self.view在首次使用時,會用loadView初始化,並觸發viewdidload完成之後,繼續self.view操做
IOS6.0中,棄用viewDidUnload和viewWillUnload…從而只能使用
didReceiveMemoryWarning
,在之前的ios中,didReceiveMemoryWarning會觸發viewDidUnload等,可是如今起,只能本身在內存警告中處理,甚至本身釋放self.view。。若是確實釋放了sefl.view=nil。則在加載時會從新觸發viewDidload
二、手工向tabviewcontroller、navigationcontroller發送viewWillAppear等系列消息,均會致使其向它的棧頂viewcontroller發同名消息。
做爲container使用的viewcontroller則無此特性, 可是在5.0之後因爲(addsubview的做用)系統發的viewWillAppear會向container及其全部childController發送
三、tableViewController的初始化過程:viewWillAppear -> tableViewDatasource method -> viewDidAppear
由於更新數據源最好在
viewWillAppear中進行,並reloadData…..
viewdidload後..
viewWillAppear先於
reloadData
4. pushcontroller後纔會觸發viewdidload
ios-隱藏狀態欄
在項目.plist文件中添加一個屬性
Status bar is initially hidden
,屬性值設置爲 YES 便可
狀態欄。。網絡鏈接顯示菊花。。
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES
一、
內存警告和
viewDidUnload
以controller爲單位,向全部controller發送(前後順序爲導航controller的出棧順序)。但前臺controller
不會收到viewDidUnload,
導航controller不是後臺controller,不會收到viewDidUnload
The view controller calls its
viewDidUnload
method to inform subclasses that the self.view were removed.
A subclass typically uses this method to release any strong references it has to self.view.
二、
When overriding the loadView method to create your views programmatically,you should not call
super.
Doing so initiates the default view-loading behavior and usually just wastes CPU cycles. Your own implementation of the
loadView
method should do all the work that is needed to create a root view and subviews for your view controller.
你在控制器中實現了 loadView 方法,那麼你可能會在應用運行的某個時候被內存管理控制調用。 若是設備內存不足的時候, view 控制器會收到 didReceiveMemoryWarning 的消息。 默認的實現是檢查當前控制器的 view 是否在使用。 若是它的 view 不在當前正在使用的 view hierarchy 裏面,且你的控制器實現了 loadView 方法,那麼這個 view 將被 release, loadView 方法將被再次調用來建立一個新的 view。
這個方法的默認實現是這樣:先尋找有關可用的nib文件的信息,根據這個信息來加載nib文件,若是沒有有關nib文件的信息,默認實現會建立一個空白的UIView對象,而後讓這個對象成爲controller的主view。
三、
If the autoresizing behaviors of views do not provide the precise layout you need, you may want to replace or supplement their behavior by providing your own custom layout code. The
UIViewController
class and the
UIView
class each define methods that are called before, during, and after this change. Here’s what happens:
-
The view controller’s view is resized to the new size.ios
-
The view controller’s viewWillLayoutSubviews method is called.網絡
-
The view controller’s view calls its layoutSubviews method.app
-
The view controller’s viewDidLayoutSubviews method is called. ide
四、
event responder
event
---------->view-->view controller-->super view
五、
Table 8-1
Methods to call to determine why a view’s appearance changed
Method Nameui |
Usagethis |
isMovingFromParent- ViewController |
You call this method inside your viewWillDisappear: and viewDidDisappear: methods to determine if the view controller’s view is being hidden because the view controller was removed from its container view controller.spa |
isMovingToParent- ViewController |
You call this method inside your viewWillAppear: and viewDidAppear: methods to determine if the view controller’s view is being shown because the view controller was just added to a container view controller..net |
isBeingPresented |
You call this method inside your viewWillAppear: and viewDidAppear: methods to determine if the view controller’s view is being shown because the view controller was just presented by another view controller.rest |
isBeingDismissed |
You call this method inside your viewWillDisappear: and viewDidDisappear: methods to determine if the view controller’s view is being hidden because the view controller was just dismissed. code |
六、if the user cancels the current operation, you can remove all objects in the chain by dismissing the first presented view controller. In other words, dismissing a view controller dismisses not only that view controller but also any view controllers it presented.
If you need to present a view controller programmatically, you must do the following:
-
Create the view controller you want to present.
-
Set the modalTransitionStyle property of the view controller to the desired value.
-
Assign a delegate object to the view controller. Typically, the delegate is the presenting view controller. The delegate is used by the presented view controllers to notify the presenting view controller when it is ready to be dismissed. It may also communicate other information back to the delegate.
-
Call the presentViewController:animated:completion: method of the current view controller, passing in the view controller you want to present.
When a view controller is presented, iOS searches for a presentation context. It starts at the presenting view controller by reading its
definesPresentationContext
property. If the value of this property is
YES,
then the presenting view controller defines the presentation context. Otherwise, it continues up through the view controller hierarchy until a view controller returns
YES
or until it reaches the window’s root view controller.
七、
Segue objects are instances of
UIStoryboardSegue
or one of its subclasses.
八、按HOME鍵後臺掛起。。不會觸發view load和appear相關的消息,因此界面不須要再次從新生成。。
9.
The first item added to the stack becomes the
root view controller
and is never popped off the stack.
When
creating
a navigation controller, you must do the following:
-
Create the root view controller for the navigation interface.
This object is the top-level view controller in the navigation stack. The navigation bar displays no back button when its view is displayed and the view controller cannot be popped from the navigation stack.
-
Create the navigation controller, initializing it using the initWithRootViewController: method.
-
Set the navigation controller as the root view controller of your window (or otherwise present it in your
interface).
When determining whether a view should be sized to fill all or most of the screen, a navigation controller considers several factors, including the following:
Is the underlying window (or parent view) sized to fill the entire screen bounds?
Is the navigation ba
r configured to be translucent
?
Is the navigation toolbar (if used) configured to be translucent?
Is the underlying view controller’s
wantsFullScreenLayout property set to YES
?
If you are creating a navigation interface and want your custom content to span most or all of the screen, here are the steps you should take:
-
Configure the frame of your custom view to fill the screen bounds.
Be sure to configure the autoresizing attributes of your view as well. The autoresizing attributes ensure that if your view needs to be resized, it adjusts its content accordingly. Alternatively, when your view is resized, you can call the setNeedsLayout method of your view to indicate that the position of its subviews should be adjusted.
-
To underlap the navigation bar,set the translucent property of your navigation controller to YES.
-
To underlap an optional toolbar, set the translucent property of the toolbar to YES.
-
To underlap the status bar, set the wantsFullScreenLayout property of your view controller to YES.
When your app launches, you can use the
setViewControllers: animated:
method to restore the navigation controller to a previous state. For example, you would use this method to return the user to the same screen they were viewing when they last quit the app.
To back to more than one level at a time, use the
popToViewController: animated:
method.
You can use the
isMovingToParentViewController
and
isMovingFromParentViewController
methods of
UIViewController
to determine if a view controller is appearing or disappearing as a result of a push or a pop.
The navigation stack and the navigation item stack are always parallel: for each content view controller on the navigation stack, its navigation item is in the same position in the navigation item stack.
For the topmost view controller, the item that is displayed on the left side of the navigation bar is determined using the following rules:
- If you assign a custom bar button item to the leftBarButtonItem property of the topmost view controller’s navigation item, that item is given the highest preference.
- If you do not provide a custom bar button item and the navigation item of the view controller one level down on the navigation stack has a valid item in its backBarButtonItem property, the navigation bar displays that item.
- If a bar button item is not specified by either of the view controllers, a default back button is used and its title is set to the value of the title property of the previous view controller—that is, the view controller one level down on the navigation stack. (If the topmost view controller is the root view controller, no default back button is displayed.)
You should create the items in the
viewDidLoad
method of your view controller.
Using Edit and Done Buttons
myViewController.navigationItem.rightBarButtonItem = [myViewController
editButtonItem];
If you include this button in your navigation bar, you must also override your view controller’s
setEditing:animated:
method and use it to adjust your view hierarchy.
To configure a toolbar for your navigation interface, you must do the following:
- Show the toolbar by setting the toolbarHidden property of the navigation controller object to NO.
- Assign an array of UIBarButtonItem objects to the toolbarItems property of each of your content view controllers, as described in 「Specifying the Toolbar Items」 (page 30).
- To hide the toolbar for a specific view controller, set the hidesBottomBarWhenPushed property of that view controller to YES
- If you want to hide the toolbar sometimes (but not always), you can call the setToolbarHidden:animated: method of the navigation controller at any time.
- a call to the setNavigationBarHidden:animated: method to create a temporary full-screen view.
10. moreNavigationController
property of
UITabBarController.
The recommended time to create a tab bar item is during the initialization of the view controller itself
If you need to prevent the user from selecting a tab, you can do so by providing a
delegate object
and implementing the
tabBarController:shouldSelectViewController:
method on that object.
you would not use your tab bar controller delegate to change the appearance of the status bar to match the style of the currently selected view. Visual changes of that nature are best handled by your content view controllers.
Preventing the Customization of Tabs
you can assign an array of view controller objects to the
customizableViewControllers
property.
This array should contain the subset of view controllers that it is all right to rearrange. View controllers not in the array are not displayed on the configuration screen and cannot be removed from the tab bar if they are already there.
Important
Adding or removing viewcontrollers in your tab bar interface also resets the array of customizable view controllers to the default value, allowing all view controllers to be customized again.
Therefore, if you make modifications to the
viewControllers
property (either directly or by calling the
setViewControllers:animated:
method) and still want to limit the customizable view controllers, you must also update the array of objects in the
customizableViewControllers
property.
To assign a badge to a tab, assign a non-nil value to the
badgeValue
property
of the corresponding tab bar item.
if (numberOfNewItems == 0)
{
self.tabBarItem.badgeValue = nil;
}
else
{
self.tabBarItem.badgeValue = [NSString stringWithFormat:@"%d", numberOfNewItems];
}
When a device orientation change occurs, the tab bar controller queries its array of view controllers. If any one of them does not support the orientation, the tab bar controller does not change its orientation.
tab bar controller can`t full screen?