1、self.view在首次使用时,会用loadView初始化,并触发viewdidload完成以后,继续self.view操作
IOS6.0中,弃用viewDidUnload和viewWillUnload…从而只能使用
didReceiveMemoryWarning
,在以前的ios中,didReceiveMemoryWarning会触发viewDidUnload等,但是现在起,只能自己在内存警告中处理,甚至自己释放self.view。。如果确实释放了sefl.view=nil。则在加载时会重新触发viewDidload
2、手工向tabviewcontroller、navigationcontroller发送viewWillAppear等系列消息,均会导致其向它的栈顶viewcontroller发同名消息。
作为container使用的viewcontroller则无此特性, 但是在5.0以后由于(addsubview的作用)系统发的viewWillAppear会向container及其所有childController发送
3、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
1、
内存警告和
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.
2、
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。
3、
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.
-
The view controller’s viewWillLayoutSubviews method is called.
-
The view controller’s view calls its layoutSubviews method.
-
The view controller’s viewDidLayoutSubviews method is called.
4、
event responder
event
---------->view-->view controller-->super view
5、
Table 8-1
Methods to call to determine why a view’s appearance changed
Method Name |
Usage |
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. |
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. |
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. |
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. |
6、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.
7、
Segue objects are instances of
UIStoryboardSegue
or one of its subclasses.
8、按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?
来源:oschina
链接:https://my.oschina.net/u/104077/blog/196621