Uinavigationcontroller is also a navigation controller, inherited from the Uiviewcontroller, a stack of the way to manage the control of the view controller, the following details about the use of Uinavigationcontroller:
1, first create a new project (not much to say) the creation of Rootviewcontroller (inherited from the Uiviewcontroller).
2. Open the AppDelegate.h file to add properties
3. Open the APPDELEGATE.M file
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) The Launchoptions method adds the Navcontroller and root view (Rootviewcontroller).
1-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {2 //Override point for customization after application launch.3 4Self.window =[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds];5Rootviewcontroller *ROOTVC =[[Rootviewcontroller alloc] init];6Rootvc.title =@"Rootviewcontroller";7 8 //Initialize Navcontroller9Self.navcontroller =[[Uinavigationcontroller alloc] init];Ten //add push action to ROOTVC One [Self.navcontroller PUSHVIEWCONTROLLER:ROOTVC animated:yes]; A //Add the navcontroller to the window - [Self.window AddSubview:self.navController.view]; - the [Self.window makekeyandvisible]; - - returnYES; -}
:
4. Add uibarbuttonitem
Note:Uibarbuttonitem is divided into Leftbarbuttonitem and Rightbarbuttonitem;
1 #import "RootViewController.h"2 3 @interfaceRootviewcontroller () {4 5Uibarbuttonitem *LeftButton;6Uibarbuttonitem *Rightbutton;7 8 }9 Ten @end One A @implementationRootviewcontroller - -- (void) Viewdidload { the [Super Viewdidload]; - //Do any additional setup after loading the view from its nib. - -LeftButton =[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemedit target:self action: @selector ( Leftbuttonaction:)]; +Self.navigationItem.leftBarButtonItem =LeftButton; - +Rightbutton =[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemcancel target:self action: @selector ( Rightbuttonaction:)]; ASelf.navigationItem.rightBarButtonItem =Rightbutton; at - -}
:
Here's another word Initwithbarbuttonsystemitem: The system comes with a button style:
Uibarbuttonsystemitemdone: Blue text button, labeled "Done";
Uibarbuttonsystemitemcancel: Text button, labeled "Cancel";
Uibarbuttonsystemitemedit: Text button, marked with "Edit";
Uibarbuttonsystemitemsave: Blue text button, labeled "Save";
Uibarbuttonsystemitemadd: Image button with a å symbol above;
Uibarbuttonsystemitemflexiblespace: Blank, the space size is variable;
Uibarbuttonsystemitemfixedspace: Blank placeholder;
Uibarbuttonsystemitemcompose: Image button with a pen and paper on it;
Uibarbuttonsystemitemreply: Image button with a reply arrow on it;
Uibarbuttonsystemitemaction: Image button with an action arrow on it;
Uibarbuttonsystemitemorganize: Image button, with a folder and a down arrow;
Uibarbuttonsystemitembookmarks: Image button with bookmark icon on it;
Uibarbuttonsystemitemsearch: Image button with spotlight icon on it;
Uibarbuttonsystemitemrefresh: Image button with a circular refresh arrow on it;
Uibarbuttonsystemitemstop: Image button with a stop Mark X on it;
Uibarbuttonsystemitemcamera: Image button with a camera on it;
Uibarbuttonsystemitemtrash: Image button with a trash bin on it;
Uibarbuttonsystemitemplay: Image button with a play icon on it;
Uibarbuttonsystemitempause: Image button with a pause icon on it;
Uibarbuttonsystemitemrewind: Image button with a rewind icon on it;
Uibarbuttonsystemitemfastforward: Image button with a fast forward icon;
5, therealization of Uibarbuttonitem events
1- (void) Leftbuttonaction: (uibarbuttonitem*) leftaction{2 3Uialertview *leftalert = [[Uialertview alloc] Initwithtitle:@"Tips"Message@"do you want to continue editing" Delegate: Self Cancelbuttontitle:@"is a"Otherbuttontitles:@"No", nil];4 [Leftalert show];5 }6 7- (void) Rightbuttonaction: (uibarbuttonitem*) rightaction{8 9Uialertview *rightalert = [[Uialertview alloc] Initwithtitle:@"Tips"Message@"Exit" Delegate: Self Cancelbuttontitle:@"is a"Otherbuttontitles:@"No", nil];Ten [Rightalert show]; One A}
:
iOS Basics (10) Use of--uinavgationcontroller (i) Uibarbuttonitem additions