[Objective-c] 019_uiviewcontroller

Source: Internet
Author: User

Uiviewcontroller is an important part of the iOS program that corresponds to the MVC design pattern C, which manages many views in the program, when the view is loaded, when the view is removed, the rotation of the interface, and so on.

1.UIViewController Create and initialize

[1]. Create and initialize with NIB file

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions  {   

[2]. Custom creation and initialization

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (nsdictionary *) launchOptions  {   

  

2.UIViewController Rotation Direction Control

    • Before IOS6, the Shouldautorotatetointerfaceorientation method controls the direction of the Uiviewcontroller separately.
-(BOOL) Shouldautorotatetointerfaceorientation: (uiinterfaceorientation) interfaceorientation {    return ( Interfaceorientation = = Uiinterfaceorientationlandscapeleft | |            Interfaceorientation = = Uiinterfaceorientationlandscaperight);}
    • IOS6 and higher, rewrite this 2 methods, iOS6 inside to rotate there are some areas needing attention, need to add supported interface orientations program support in the Info.plist file.
-(BOOL) shouldautorotate {    return YES;} -(Nsuinteger) Supportedinterfaceorientations{return uiinterfaceorientationmaskportrait;//Erect}

3.UIViewController switching

    • Uiviewcontroller the call between itself
Uiviewcontroller *test = [[Uiviewcontroller alloc] init];//jump  Test[self.window.rootviewcontroller Presentviewcontroller:test animated:yes completion:^{    NSLog (@ "present complete");}];/ /Return to self  (test controller disappears) [Self.window.rootViewController Dismissviewcontrolleranimated:yes completion:^{        NSLog (@ "dismiss complete");}];
    • Uinavigationcontrolle the controller of the navigation controllers to control the switching between Viewcontrller (hierarchical logical Viewcontrller)
Jump [Self.navigationcontroller pushviewcontroller:test animated:yes]; return to [Self.navigationcontroller Popviewcontrolleranimated:yes];

From the above points can be seen, uiviewcontroller between the switch management, the correct approach is "who pollution who governance."

This site article is for baby bus SD. Team Original, reproduced must be clearly noted: (the author's official website: Baby bus )

Reprinted from "Baby bus Superdo Team" original link: http://www.cnblogs.com/superdo/p/4771718.html

[Objective-c] 019_uiviewcontroller

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.