iOS Basics (11) Use of--uinavgationcontroller (ii) page switching

Source: Internet
Author: User

In the previous article, add Uibarbuttonitem, then say the interface switch;

1, first we add a button in the Rootviewcontroller just now to implement the jump:

Open rootviewcontroller.m (I'll keep writing) and add a jump button:

:

2, button action realization, a new newviewcontroller inherit from Uiviewcontroller; Pushviewcontroller to Navigationcontroller;

#import " NewViewController.h "
-(void) nextaction{        *NEWVC = [[Newviewcontroller alloc] init];    [Self.navigationcontroller PUSHVIEWCONTROLLER:NEWVC Animated:yes];     @" Newviewcontroller " ;}

Click Button,back to bring the system to its own button;

If you do not want to use the system's own button, we can customize the button:

Uibarbuttonitem *backbutton = [[Uibarbuttonitem alloc] Initwithtitle:@ " back "  Style:uibarbuttonitemstyledone Target:nil Action:nil];     = Backbutton;

3, the title of the custom:

1 #import "NewViewController.h"2 3 @interfaceNewviewcontroller ()4 5 @end6 7 @implementationNewviewcontroller8 9- (void) Viewdidload {Ten [Super Viewdidload]; One     //Do any additional setup after loading the view. A  -UILabel *title =[[UILabel alloc] init]; -Title.text =@"title"; theTitle.font = [Uifont systemfontofsize: -]; - [title SizeToFit]; -Self.navigationItem.titleView =title; -      +}

:

4. If you want to place more than one button:

Nsarray *colorarray = @[@ " black "@ " white "@ " Gray "  ];     *segmentctrl = [[Uisegmentedcontrol alloc] initwithitems:colorarray];     1 ;     = [Uicolor redcolor];     = Segmentctrl;

:

To add a click response event:

[Segmentctrl addtarget:self Action: @selector (segmentaction:) forcontrolevents:uicontroleventvaluechanged];

- (void) Segmentaction: (ID) segment{Switch([segment Selectedsegmentindex]) { Case 0: {Uialertview*alert = [[Uialertview alloc] Initwithtitle:@"Tips"Message@"you have selected the color black" Delegate: Self Cancelbuttontitle:@"is a"Otherbuttontitles:@"No", nil];        [Alert show]; }             Break;  Case 1: {Uialertview*alert = [[Uialertview alloc] Initwithtitle:@"Tips"Message@"you have selected the color white" Delegate: Self Cancelbuttontitle:@"is a"Otherbuttontitles:@"No", nil];                    [Alert show]; }             Break;  Case 2: {Uialertview*alert = [[Uialertview alloc] Initwithtitle:@"Tips"Message@"you have selected a color gray" Delegate: Self Cancelbuttontitle:@"is a"Otherbuttontitles:@"No", nil];                    [Alert show]; }             Break; default:             Break; }}

:

iOS Basics (11) Use of--uinavgationcontroller (ii) page switching

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.