Swift Uinavigationcontroller Navigation Controller

Source: Internet
Author: User
Tags reserved set background uikit

I. Create a project//slightly

Two. Create a View controller (shortcut: Do not go to create a swift file, just do the following


On the code (with comments) Appdelegate.swift

//

Appdelegate.swift

Swift Uinavigationcontroller Navigation Controller

//

Created by Zhangbiao on 14-6-16.

Copyright (c) 2014 ideals. All rights reserved.

//


Import UIKit


@UIApplicationMain

Class Appdelegate:uiresponder, Uiapplicationdelegate {

var Window:uiwindow?



Func application (application:uiapplication, Didfinishlaunchingwithoptions launchoptions:nsdictionary?), Bool {

Self.window = UIWindow (Frame:UIScreen.mainScreen (). Bounds)

Override point for customization after application launch.

self.window!. BackgroundColor = Uicolor.whitecolor ()

self.window!. Makekeyandvisible ()

Define a View Controller

Let ONE_VC = Oneviewcontroller (Nibname:nil,bundle:nil);

Creating a navigation controller

Let Nvc=uinavigationcontroller (ROOTVIEWCONTROLLER:ONE_VC);

Setting the root view

self.window!. ROOTVIEWCONTROLLER=NVC;

return True

}

Func applicationwillresignactive (application:uiapplication) {

Sent when the application are about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as a incoming phone call or SMS message) or when the US Er quits the application and it begins the transition to the background state.

Use the This method to the pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

}


Func Applicationdidenterbackground (application:uiapplication) {

Use the This method to release the shared resources, save user data, invalidate timers, and store enough application state info Rmation to the restore your application to the it is terminated later.

If your application supports background execution, this method is called instead of Applicationwillterminate:when the User quits.

}


Func Applicationwillenterforeground (application:uiapplication) {

Called as part of the transition from the background to the inactive state; Here's can undo many of the changes made on entering the background.

}


Func applicationdidbecomeactive (application:uiapplication) {

Restart any tasks this were paused (or not yet started) while the application is inactive. If the application is previously in the background, optionally refresh the user interface.

}


Func applicationwillterminate (application:uiapplication) {

Called when the application are about to terminate. Save data if appropriate. See also Applicationdidenterbackground:.

}



}


Oneviewcontroller.swift


//

Oneviewcontroller.swift

Swift Uinavigationcontroller Navigation Controller

//

Created by Zhangbiao on 14-6-16.

Copyright (c) 2014 ideals. All rights reserved.

//


Import UIKit


Class Oneviewcontroller:uiviewcontroller {


Init (nibname nibnameornil:string?, bundle Nibbundleornil:nsbundle?) {

Super.init (Nibname:nibnameornil, Bundle:nibbundleornil)

Custom initialization

}

//

Override Func Viewdidload () {

Super.viewdidload ()

Set Navigation bar title

Self.title= "one";

Item title//item style//target all//nxet event-triggered method name

Let Nextitem=uibarbuttonitem (title: "Next Page", Style:.) Plain,target:self,action: "Next");

Add to the navigation bar

Self.navigationItem.rightBarButtonItem = Nextitem;


}

Item Event

Func Next ()

{

println ("Click on Next Page");

Define a controller

Let TOW_VC = Towviewcontroller ();

Push into the next view

Self.navigationController.pushViewController (tow_vc,animated:true);

}

Override Func didreceivememorywarning () {

Super.didreceivememorywarning ()

Dispose of any resources the can be recreated.

}


/*

#pragma mark-navigation


In a storyboard-based application, you'll often want to do a little preparation before navigation

Override Func Prepareforsegue (Segue:uistoryboardsegue, sender:anyobject?) {

Get The new view controller using [Segue Destinationviewcontroller].

Pass the selected object to the new view controller.

}

*/


}
Towviewcontroller.swift

//

Towviewcontroller.swift

Swift Uinavigationcontroller Navigation Controller

//

Created by Zhangbiao on 14-6-16.

Copyright (c) 2014 ideals. All rights reserved.

//


Import UIKit


Class Towviewcontroller:uiviewcontroller {

//

Init (nibname nibnameornil:string?, bundle Nibbundleornil:nsbundle?) {

Super.init (Nibname:nibnameornil, Bundle:nibbundleornil)

Custom initialization

//    }


Override Func Viewdidload ()

{

Super.viewdidload ()

Self.title= "Tow";

Create a button

var But=uibutton (Frame:cgrect (x:110,y:100,width:100,height:40));

Set tag

but.tag=1001;

Set Title

But.settitle ("Back to Previous page", Forstate:.) Normal);

Add Event

But.addtarget (self,action: "Butclick:", forControlEvents:. Touchupinside);

Set Background color

But.backgroundcolor=uicolor.bluecolor ();

Add to attempt on

Self.view.addSubview (But);

var But1=uibutton (Frame:cgrect (x:110,y:200,width:100,height:40));

Set but tag

but1.tag=1002;

Set Title

But1.settitle ("Next page", Forstate:. Normal);

Add Event

But1.addtarget (self,action: "Butclick:", forControlEvents:. Touchupinside);

Set Background color

But1.backgroundcolor=uicolor.bluecolor ();

Add to view

Self.view.addSubview (BUT1);

Related Article

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.