[iOS Learning Notes] Uinavigationcontroller Demo

Source: Internet
Author: User

//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

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.