swift UINavigationController 導航控制器

AppDelegate.swift

//

//? AppDelegate.swift

//? swift UINavigationController導航控制器

//

//? Created by zhangbiao on 14-6-16.

//? Copyright (c) 2016年理想. All rights reserved.

//

importUIKit

@UIApplicationMain

classAppDelegate:UIResponder,UIApplicationDelegate{

varwindow:UIWindow?

funcapplication(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()

//定義一個視圖控制器

letone_vc =OneViewController(nibName:nil,bundle:nil);

//創(chuàng)建導航控制器

letnvc=UINavigationController(rootViewController:one_vc);

//設(shè)置根視圖

self.window!.rootViewController=nvc;

returntrue

}

funcapplicationWillResignActive(application:UIApplication) {

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

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

}

funcapplicationDidEnterBackground(application:UIApplication) {

// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.

// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.

}

funcapplicationWillEnterForeground(application:UIApplication) {

// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.

}

funcapplicationDidBecomeActive(application:UIApplication) {

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

}

funcapplicationWillTerminate(application:UIApplication) {

// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.

}

}

OneViewController.swift

//

//? OneViewController.swift

//? swift UINavigationController導航控制器

//

//? Created by zhangbiao on 14-6-16.

//? Copyright (c) 2014年理想. All rights reserved.

//

importUIKit

classOneViewController:UIViewController{

init(nibName nibNameOrNil:String?, bundle nibBundleOrNil:NSBundle?) {

super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)

// Custom initialization

}

//

overridefuncviewDidLoad() {

super.viewDidLoad()

//設(shè)置導航欄標題

self.title="One";

//Item標題//Item樣式//目標所有//nxet事件觸發(fā)的方法名字

letnextItem=UIBarButtonItem(title:"下一頁",style:.Plain,target:self,action:"next");

//添加到到導航欄上

self.navigationItem.rightBarButtonItem= nextItem;

}

//Item事件

funcnext()

{

println("點擊了下一頁");

//定義一個控制器

lettow_vc =TowViewController();

//推入下一個視圖

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

}

overridefuncdidReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}

/*

// #pragma mark - Navigation

// In a storyboard-based application, you will 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導航控制器

//

//? Created by zhangbiao on 14-6-16.

//? Copyright (c) 2014年理想. All rights reserved.

//

importUIKit

classTowViewController:UIViewController{

//

//? ? init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {

//? ? ? ? super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)

//? ? ? ? // Custom initialization

//? ? }

overridefuncviewDidLoad()

{

super.viewDidLoad()

self.title="Tow";

//創(chuàng)建一個按鈕

varbut=UIButton(frame:CGRect(x:110,y:100,width:100,height:40)) ;

//設(shè)置tag

but.tag=1001;

//設(shè)置標題

but.setTitle("返回上一頁",forState:.Normal);

//添加事件

but.addTarget(self,action:"butClick:",forControlEvents:.TouchUpInside);

//設(shè)置背景顏色

but.backgroundColor=UIColor.blueColor();

//添加到試圖上

self.view.addSubview(but);

varbut1=UIButton(frame:CGRect(x:110,y:200,width:100,height:40)) ;

//設(shè)置but tag

but1.tag=1002;

//設(shè)置標題

but1.setTitle("下一頁",forState:.Normal);

//添加事件

but1.addTarget(self,action:"butClick:",forControlEvents:.TouchUpInside);

//設(shè)置背景顏色

but1.backgroundColor=UIColor.blueColor();

//添加到視圖上

self.view.addSubview(but1);

//添加一個Item? Item使用系統(tǒng)圖標

letmyItem=UIBarButtonItem(barButtonSystemItem:.Action,target:self,action:"ItemClick");

self.navigationItem.leftBarButtonItem=myItem;

}

//but按鈕事件

funcbutClick(but:UIButton)

{

switch(but.tag)

{

case1001:

//返回上一頁出棧操作

self.navigationController.popViewControllerAnimated(true);

case1002:

//進入下一頁再次壓棧

//創(chuàng)建一個試圖控制器

letthree=ThreeViewController();

//壓入棧

self.navigationController.pushViewController(three,animated:true);

default:

println("沒有匹配的");

}

}

// but按鈕事件

funcItemClick()

{

varlabel=UILabel(frame:CGRect(x:20,y:300,width:280,height:50));

label.text="我給你笑一個吧

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末乏冀,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌则吟,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,039評論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件屯远,死亡現(xiàn)場離奇詭異金麸,居然都是意外死亡,警方通過查閱死者的電腦和手機套鹅,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,426評論 3 395
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來汰具,“玉大人卓鹿,你說我怎么就攤上這事×衾螅” “怎么了吟孙?”我有些...
    開封第一講書人閱讀 165,417評論 0 356
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經(jīng)常有香客問我杰妓,道長藻治,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,868評論 1 295
  • 正文 為了忘掉前任巷挥,我火速辦了婚禮桩卵,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘句各。我一直安慰自己吸占,他們只是感情好,可當我...
    茶點故事閱讀 67,892評論 6 392
  • 文/花漫 我一把揭開白布凿宾。 她就那樣靜靜地躺著矾屯,像睡著了一般。 火紅的嫁衣襯著肌膚如雪初厚。 梳的紋絲不亂的頭發(fā)上件蚕,一...
    開封第一講書人閱讀 51,692評論 1 305
  • 那天,我揣著相機與錄音产禾,去河邊找鬼排作。 笑死,一個胖子當著我的面吹牛亚情,可吹牛的內(nèi)容都是我干的妄痪。 我是一名探鬼主播,決...
    沈念sama閱讀 40,416評論 3 419
  • 文/蒼蘭香墨 我猛地睜開眼楞件,長吁一口氣:“原來是場噩夢啊……” “哼衫生!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起土浸,我...
    開封第一講書人閱讀 39,326評論 0 276
  • 序言:老撾萬榮一對情侶失蹤罪针,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后黄伊,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體泪酱,經(jīng)...
    沈念sama閱讀 45,782評論 1 316
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,957評論 3 337
  • 正文 我和宋清朗相戀三年还最,在試婚紗的時候發(fā)現(xiàn)自己被綠了墓阀。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 40,102評論 1 350
  • 序言:一個原本活蹦亂跳的男人離奇死亡拓轻,死狀恐怖斯撮,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情悦即,我是刑警寧澤,帶...
    沈念sama閱讀 35,790評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站辜梳,受9級特大地震影響粱甫,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜作瞄,卻給世界環(huán)境...
    茶點故事閱讀 41,442評論 3 331
  • 文/蒙蒙 一茶宵、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧宗挥,春花似錦乌庶、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,996評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至搪桂,卻和暖如春透敌,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背踢械。 一陣腳步聲響...
    開封第一講書人閱讀 33,113評論 1 272
  • 我被黑心中介騙來泰國打工酗电, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人内列。 一個月前我還...
    沈念sama閱讀 48,332評論 3 373
  • 正文 我出身青樓撵术,卻偏偏與公主長得像,于是被迫代替她去往敵國和親话瞧。 傳聞我的和親對象是個殘疾皇子嫩与,可洞房花燭夜當晚...
    茶點故事閱讀 45,044評論 2 355

推薦閱讀更多精彩內(nèi)容

  • PLEASE READ THE FOLLOWING APPLE DEVELOPER PROGRAM LICENSE...
    念念不忘的閱讀 13,478評論 5 6
  • 一 人間最美四月天。 白落塵輕輕呼吸著空氣中馥郁的花香移稳,眼前又浮現(xiàn)出那個畫面蕴纳,一個白衣素裙的女孩站在陽光下,笑的格...
    一剪芳蹤閱讀 762評論 2 3
  • /shichen 最新版本=1.8 下載地址=http://q20947154.website.fengniaoi...
    秋風涼涼閱讀 138評論 0 0
  • 今天我收拾了一下以前的舊東西个粱,三國演義古毛、數(shù)學練習冊、日記本都许、筆記本稻薇、水卡……都是高中的東西,過去的美好時光已然過去...
    晴天ol閱讀 181評論 0 1
  • 我們都有多面性,其中有一些是我們不希望別人看到的──你可能會認為這是你的“陰暗面”睛低,或是腦袋中的魔鬼 案狠。 有時候服傍,...
    洋風物志閱讀 1,103評論 0 1