//APPDELEGATE.M
-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions {//Override point for customization after application launch.Self.window =[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]; Self.window.backgroundColor=[Uicolor Whitecolor]; Rootviewcontroller*rootview=[[Rootviewcontroller alloc]init]; Uinavigationcontroller*nav =[[Uinavigationcontroller Alloc]initwithrootviewcontroller:rootview]; [_window Setrootviewcontroller:nav]; [Nav release]; [Rootview release]; returnYES;}
//ROOTVIEWCONTROLLER.M- (void) Viewdidload {//Do any additional setup after loading the view.[Super Viewdidload]; //Do any additional setup after loading the view.[Self.navigationController.navigationBar Settranslucent:no];//set the translucency of the NavigationbarSelf.title=@"Rootviewcontroller";//set the caption that appears on the Navigationbar[Self.navigationController.navigationBar setbartintcolor:[uicolor purplecolor];//set the color of the NavigationbarSelf.navigationItem.leftBarButtonItem= [[Uibarbuttonitem alloc]initwithbarbuttonsystemitem:uibarbuttonitemstyledone target:self Action:Nil];//Set Navigationbar left buttonSelf.navigationItem.rightBarButtonItem= [[Uibarbuttonitem alloc]initwithbarbuttonsystemitem:uibarbuttonitemstyleplain target:self Action:Nil];//Set Navigationbar right button[Self.navigationController.navigationBar settintcolor:[uicolor whitecolor];//set the left and right button font color on Navigationbar//Self.navigationItem.rightBarButtonItem settarget:<# (ID) #>//Add a button dynamicallyUIButton*button =[UIButton Buttonwithtype:uibuttontyperoundedrect]; Button.frame= CGRectMake (0, -, -, -); [Button Settitle:@"the newly added dynamic button"Forstate:uicontrolstatenormal]; Button.backgroundcolor=[Uicolor Clearcolor]; Button.tag= -; [Button addtarget:self action: @selector (clicked:) Forcontrolevents:uicontroleventtouchupinside]; [Self.view Addsubview:button]; }- (void) Clicked: (ID) sender{Secondviewcontroller*second =[[Secondviewcontroller alloc]init]; [Self.navigationcontroller Pushviewcontroller:second Animated:yes]; //second.str = @ "hello!!";[Second release];}//This is the response function of the new button.-(Ibaction) buttonclicked: (ID) Sender {Uialertview*alert = [[Uialertview alloc] Initwithtitle:@"Tips"message:@"Click the dynamic button! " Delegate: Self cancelbuttontitle:@"Determine"Otherbuttontitles:nil]; [Alert show]; [Alert release];}
Uinavigationcontroller Navigation page
Uinavigationcontroller *nav = [[Uinavigationcontroller Alloc]initwithrootviewcontroller:rootview];
Button response:
[Button addtarget:self action: @selector (clicked:) Forcontrolevents:uicontroleventtouchupinside];
Response Method Signature:-(void) clicked: (ID) Sender
[iOS Learning note] Uinavigationcontroller Demo