iOS basic-uinavigationcontroller, interface communication

Source: Internet
Author: User

Uinavigationcontroller Navigation Controller

is one of the most commonly used multi-view controllers in iOS and is used to manage multiple view controllers

The navigation controller can be considered as the controller of the management controller , which mainly manages the controller with hierarchical relationship.

The navigation controller manages the control of the view controller in a stack, with at least one managed view controller, which we call the root view controller of the navigation controller

stack and stack pushviewcontroller:animated: Go to the next view controller

Popviewcontrolleranimated: Return to previous view controller

Poptoviewcontroller:animated: Returns to the specified view controller

Poptorootviewcontrolleranimated: Return to the root view controller

Common Properties

Viewcontrollers: All controllers in the stack

Topviewcontroller: Controller at the top of the stack

Visibleviewcontroller: The controller currently being displayed

Navigationbar: Navigation bar

Custom Uinavigationbar

navigationbar--navigation Bar, iOS7 after the default is transparent

Navigationbar in the case of transparency, a portion of the area is coincident with the Contentview

Navigationbar in the case of opacity, Contentview follows Navigationbar.

Navigationbar Vertical screen under the default height of 44, horizontal screen under the default height of 32

Bartintcolor: Set the color of the navigation bar

Setbackgroundimage:forbarmetrics: Navigation bar plus background image

Uivavigationitem

The M in MVC, which encapsulates the data to be displayed on the Uinaviationbar

Title: Caption

Titleview: Title View

Leftbarbuttonitem: Left button

Rightbarbuttonitem: Right button

Uibarbuttonitem

An M in MVC that defines the trigger event for the button on the Uinavigationitem, the appearance

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {    Self.window = [[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]];    Override point for customization after application launch.    Self.window.backgroundColor = [Uicolor Whitecolor];    [Self.window makekeyandvisible];    Rootviewcontroller *MVC = [[Rootviewcontroller alloc] init];    Uinavigationcontroller *nav = [[Uinavigationcontroller alloc] INITWITHROOTVIEWCONTROLLER:MVC];    Self.window.rootViewController = nav;    [MVC release];                    [Nav release]; return YES;}    -(void) viewdidload {[Super viewdidload];    Self.view.backgroundColor = [Uicolor Graycolor];    UIButton *btn = [UIButton buttonwithtype:uibuttontyperoundedrect];    Btn.layer.borderWidth = 1;    Btn.layer.cornerRadius = 5;    Btn.frame = CGRectMake (20, 80, 335, 50);    [BTN settitle:@ "push to the next page" Forstate:uicontrolstatenormal]; [Btn addtarget:self Action: @selector (Btnclick) Forcontrolevents:uicontroleventtouchupinside];    [Self.view ADDSUBVIEW:BTN];        Self.navigationItem.title = @ "First Level interface";    Nav Bar height 44, status bar Uiimageview *imageview = [[Uiimageview alloc] Initwithframe:cgrectmake (0, 0, 375, 44)];    UIImage *image = [UIImage imagenamed:[nsstring stringwithformat:@ "5.png"];    Imageview.image = image;    [Self.navigationController.navigationBar Addsubview:imageview]; Only when the background image height is 44, it will only cover the navigation bar, in other cases will be covered by the navigation bar and status bar [Self.navigationController.navigationBar setbackgroundimage:[uiimage                imagenamed:@ "5.png"] forbarmetrics:uibarmetricsdefault]; }//Hidden status bar-(BOOL) prefersstatusbarhidden{return NO;    -(void) btnclick{secondviewcontroller *svc = [[Secondviewcontroller alloc] init];    [Self.navigationcontroller pushviewcontroller:svc Animated:yes];    Svc.currenttitle = Self.navigationItem.title;    Svc.delegate = self;            [Svc release]; }-(void) Sendbtntitle: (NSString *) title{self.navigationItem.title = title;}

Interface Communication

Property pass-through value proxy pass-through value

Proxy value (forward value from backward: Data from second page to first page)

Idea: ①, setting up the proxy on the second page, and proxy properties

@protocol sendvaluedelegate <nsobject>-(void) SendText: (NSString *) text; @end @interface Tiredviewcontroller: Uiviewcontroller@property (nonatomic,assign) id<sendvaluedelegate> delegate; @end

Ii

-(void) btn2click{    [Self.navigationcontroller Popviewcontrolleranimated:yes];    if ([_delegate respondstoselector: @selector (sendText:)]) {        [_delegate sendtext:_textfiled.text];}    }

③ first page receive agent, implementation method

@interface secondviewcontroller:uiviewcontroller<sendvaluedelegate>

④ Implementing Proxy methods

-(void) SendText: (NSString *) text{    self.label2.text = text;}

iOS basic-uinavigationcontroller, interface communication

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.