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
//? 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
//? 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="我給你笑一個吧