////main.m//Hello////Created by Lishujun on 14-8-28.//Copyright (c) 2014 Lishujun. All rights reserved.//#import<UIKit/UIKit.h>@interfaceTestviewcontroller:uiviewcontroller@end@implementationTestviewcontroller-(void) loadview{NSLog (@"Load View"); //Create a View objectUIView *contentview =[[UIView Alloc]initwithframe:[[uiscreen Mainscreen] applicationframe]; Contentview.backgroundcolor=[Uicolor Lightgraycolor]; Self.view=Contentview;}@end//--------------View Controller Object--------------@interfacehelloworldviewcontroller:uiviewcontroller{Uitoolbar*ToolBar;}@end@implementationHelloworldviewcontroller-(void) loadview{NSLog (@"Load View"); //Create a View objectUIView *contentview =[[UIView Alloc]initwithframe:[[uiscreen Mainscreen] applicationframe]; Contentview.backgroundcolor=[Uicolor Lightgraycolor]; Self.view=Contentview; //sets the toolbar and displays[self setnavbarandshow]; [Self setusertoolbarandshow];}//-----------Set the navigation bar and display the------------------(void) setnavbarandshow{Self.navigationItem.leftBarButtonItem= [[Uibarbuttonitem alloc] Initwithtitle:@"Next"Style:uibarbuttonitemstyleplain target:self Action: @selector (Pushview:)]; Self.navigationItem.rightBarButtonItem= [[Uibarbuttonitem alloc] Initwithtitle:@"Prev"Style:uibarbuttonitemstyleplain target:self Action: @selector (Popview:)]; [Self.navigationcontroller Setnavigationbarhidden:no]; //show the previously hidden navigation bar}-(void) Pushview: (ID) sender{NSLog (@"Push View"); [Self.navigationcontroller Pushviewcontroller:[[testviewcontroller Alloc]init] animated:yes];}-(void) Popview: (ID) sender{NSLog (@"Pop View"); [Self.navigationcontroller Popviewcontrolleranimated:yes];}//------------Set the toolbar and display the---------------(void) setnavtoolbarandshow{//sets the toolbar on the Navigationcontroller and displaysUibarbuttonitem *one =[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemadd target:nil Action:nil]; Uibarbuttonitem*two =[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitembookmarks target:nil Action:nil]; Uibarbuttonitem*three =[[Uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemaction target:nil Action:nil]; Uibarbuttonitem*four =[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemedit target:nil Action:nil]; Uibarbuttonitem*flexitem =[[Uibarbuttonitem alloc] initwithbarbuttonsystemitem:uibarbuttonsystemitemflexiblespace target:nil Action:nil] ; [Self Settoolbaritems:[nsarray arraywithobjects:flexitem, one, Flexitem, I, Flexitem, three, Flexitem, four, FlexItem, Nil]]; [Self.navigationcontroller Settoolbarhidden:no animated:no];}-(void) setusertoolbarandshow{//set up a custom Toolbal[Self.navigationcontroller Settoolbarhidden:yes Animated:yes]; Uibarbuttonitem*addbutton =[[Uibarbuttonitem alloc] Initwithbarbuttonsystemitem:uibarbuttonsystemitemsearch target:nil Action:nil]; ToolBar= [[Uitoolbar alloc] Initwithframe:cgrectmake (0.0, Self.view.frame.size.height-toolbar.frame.size.height-44.0, Self.view.frame.size.width,44.0)]; [ToolBar Setbarstyle:uibarstyledefault]; Toolbar.autoresizingmask=Uiviewautoresizingflexibletopmargin; [ToolBar Setitems:[nsarray Arraywithobject:addbutton]; [Self.view Addsubview:toolbar];}@end//----------------The delegate object--------------------@interfaceHelloworldappdelegate:nsobject <UIApplicationDelegate>{iboutlet UIWindow*window;} @property (nonatomic, retain) UIWindow*window; @property (nonatomic, retain) Uinavigationcontroller*nav;@end@implementationhelloworldappdelegate@synthesizewindow;@synthesizenav;-(void) Applicationdidfinishlaunching: (UIApplication *) application{Self.window=[[UIWindow alloc] Initwithframe:[[uiscreen Mainscreen]bounds]]; Helloworldviewcontroller*viewcontroller =[[Helloworldviewcontroller alloc]init]; Self.nav=[[Uinavigationcontroller Alloc]initwithrootviewcontroller:viewcontroller]; [Self.nav Setnavigationbarhidden:yes]; //hide the navigation bar at the top of the view[Self.nav Settoolbarhidden:yes];//hide the toolbar at the bottom of the viewSelf.window.rootViewController=Self.nav; [Self.window makekeyandvisible];}@end//---------------Program Entry---------------------intMainintargcChar*argv[]) {@autoreleasepool {returnUiapplicationmain (argc, argv, Nil,@"helloworldappdelegate"); }}
IOS: Toolbars and navigation bars for the navigation bar