The file directory is as follows: Basic navigation Order: root, First, Second, third. Where Firstviewcontroller as the rootview of the navigation stack
1, create navigation.
If you want to direct the navigation navigation as a starting view of the project, Put the Nav attribute in the RootViewController.h file in the AppDelegate.h, and then copy the action code from the ROOTVIEWCONTROLLER.M file to APPDELEGATE.M in the Didfinishlaunchingwithoptions method, and finally set the Self.window.rootViewController Properties of the Uinavigationcontroller type Nav can be
In the RootViewController.h file
1 #import <UIKit/UIKit.h> 2 @class firstviewcontroller; 3 4 @interface rootviewcontroller:uiviewcontroller 5 6 @property (Strong, nonatomic) Uinavigationcontroller * Nav 7 8-(ibaction) Btnclick: (UIButton *) sender; 9 @end
In a random custom action in the ROOTVIEWCONTROLLER.M file:
1-(ibaction) Btnclick: (UIButton *) Sender {2 3//Create a Viewcontroller 4 firstviewcontroller *fristview = [[[Firstviewcontroller alloc] init] autorelease]; 5 6 7//Initialize Uinavigationcontroller (mode one) 8 Self.nav = [[[Uinavigationcontroller alloc] Initwithrootviewcont Roller:fristview] autorelease]; 9 10 11//Initialize Uinavigationcontroller (mode two)//Self.nav = [[[[Uinavigationcontroller alloc] init] Autorelease ];13//[Self.nav Pushviewcontroller:fristview animated:yes];14 15 16//Initialize Uinavigationcontroller (mode three, fail, xib file plus Download failed, cause temporarily unknown) Self.nav = [[[Uinavigationcontroller alloc] initwithnibname:@ "Firstviewcontroller" Bundle:nil] Autore lease];18 19 20//Jump to Firstview page [self presentViewController:self.nav animated:yes completion:nil];22 23 24//This is generally used to add some small controls to the view, such as button label TextField, not suitable for page jump//[Self.view AddSubview:self.nav.view ];26}
2, set the Navigationitem property of Viewcontroller and toolbar, ToolbarItem
(1) The navigation property and the ToolbarItem property of the Firstviewcontroller. The code is in FIRSTVIEWCONTROLLER.M's Viewdidload method.
Each viewcontroller has a Navigationitem attribute (which is only valid if loaded into the navigation stack). There are also 5 properties in the Navigationitem attribute: Leftbarbuttonitem, Rightbarbuttonitem, and Backbarbuttonitem of the Uibarbuttonitem type, The title of the NSString type (or Titleview of the Viewcontroller property), prompt.
1-(void) Viewdidload 2 {3 [Super Viewdidload]; 4//Do any additional setup after loading the view from its NIB . 5 6//The following two lines of code effect the same, but seems to set the Navigationitem.title after the title will be no effect 7 Self.navigationItem.title = @ "Home 123"; 8 Self.title = @ "Home"; 9 10//Add more lines to title, but this will cause the width of the navigation bar to widen one//self.navigationItem.prompt = @ "Prompt"; 12 13//Settings Rightbarbut Tonitem14 Uibarbuttonitem *rightbar = [[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem: Uibarbuttonsystemitemaction target:self Action: @selector (Btnclick:)] autorelease];15 16 Self.navigationItem.rightBarButtonItem = rightbar;17 18// Modify the title of the Backbarbuttonitem. This backbarbutton is displayed on the left side of the tabbar of the next push in the view of the//action can be set to nil, this is the action is the default action, That is, return to this view20 self.navigationItem.backBarButtonItem = [[[[Uibarbuttonitem alloc] initwithtitle:@ "Back" style: Uibarbuttonitemstyleplain target:self Action:nil] autorelease];21 22 23 24//Set toolbar is visible (for the entire navigation stack The view works in the global role) 25 Self.navigationController.toolbarHidden = no;26 Uibarbuttonitem *three = [[Uibarbuttonitem alloc] Initwithbar Buttonsystemitem:uibarbuttonsystemitemaction target:nil action:nil];28 Uibarbuttonitem *four = [[UIBarButtonItem allo C] Initwithbarbuttonsystemitem:uibarbuttonsystemitemedit target:nil action:nil];29 UIBarButtonItem *flexItem = [UIBa Rbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemflexiblespace target:nil action:nil];30 The Oolbar is a common view of the entire navigation stack, but the items on the toolbar are the only 32//that are owned by each view, and now only the toolbaritem of the current view is set. It is not related to other view toolbaritme [self Settoolbaritems:[nsarray arraywithobjects:flexitem, three, Flexitem, four, Flexitem , nil]];34 [Three release];36 [Four release];37 [Flexitem release];38 39 40}
The page works as follows:
(2), Secondviewcontroller's Navigationitem and ToolbarItem
The code is in the Viewdidload method.
1-(void) Viewdidload 2 {3 [Super Viewdidload]; 4//Do any additional setup after loading the view from it s nib. 5 6//Set left/right Barbutton 7 Uibarbuttonitem *rightbar = [[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbutt Onsystemitemaction target:self Action: @selector (Gotothird:)] autorelease]; 8 9 Uibarbuttonitem *leftbar = [[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemaction Target:self Action: @selector (Gotothird:)] autorelease];10 Self.navigationItem.rightBarButtonItem = rightbar;12 Self.navigationItem.leftBarButtonItem = leftbar;13 14//Current view is not rootview in the navigation stack, so put the Viewpush to navigation Stack, Tabbar to the left will show backbarbutton15//If the current view is set to Leftbarbutton, will be Backbarbutton cover out, want to display both, you need to set the following: 16 Self.navigationItem.leftItemsSupplementBackButton = yes;17 18 19 20//Set the toolbar of the current view to be visible. Because it's possible from a toolbar Invisible VI EW navigates to current view21 Self.navigationController.toolbarHidden = no;22}
The effect is as follows:
(3), Thirdviewcontroller's Navigationitem and ToolbarItem
1-(void) Viewdidload 2 {3 [Super Viewdidload]; 4 self.title = @ "Third page"; 5 //Do any additional setup after Loa Ding the view from its nib. 6 7 //Hide the current view of toolbar 8 Self.navigationController.toolbarHidden = YES; 9 //Set Toolbar11 Uibarbuttonitem *rightbar = [[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemdone Target:self Action: @selector (Gotorootview)] autorelease];12 self.navigationItem.rightBarButtonItem = RIGHTBAR;14 //Nsarray *array = @[@ "Ribs", @ "Steak"];16 //Set Titleview, will overwrite Title18 Uisegmentedcontrol *segment = [[[Uisegmentedcontrol alloc] initwithitems:@[@ ' ribs ', @ ' Steak ']] autorelease];19 Segment.segmentedcontrolstyle = uisegmentedcontrolsegmentcenter;20 Self.navigationItem.titleView = SEGMENT;22}
The effect is as follows:
Barbuttonitem's style and effect correspond to the following:
Transferred from: http://www.cnblogs.com/zouzf/archive/2013/01/17/2864506.html
IOS Learning to develop custom Uinavigationcontroller navigation