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);
//创建导航控制器
letnvc=UINavigationController(rootViewController:one_vc);
//设置根视图
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()
//设置导航栏标题
self.title="One";
//Item标题//Item样式//目标所有//nxet事件触发的方法名字
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";
//创建一个按钮
varbut=UIButton(frame:CGRect(x:110,y:100,width:100,height:40)) ;
//设置tag
but.tag=1001;
//设置标题
but.setTitle("返回上一页",forState:.Normal);
//添加事件
but.addTarget(self,action:"butClick:",forControlEvents:.TouchUpInside);
//设置背景颜色
but.backgroundColor=UIColor.blueColor();
//添加到试图上
self.view.addSubview(but);
varbut1=UIButton(frame:CGRect(x:110,y:200,width:100,height:40)) ;
//设置but tag
but1.tag=1002;
//设置标题
but1.setTitle("下一页",forState:.Normal);
//添加事件
but1.addTarget(self,action:"butClick:",forControlEvents:.TouchUpInside);
//设置背景颜色
but1.backgroundColor=UIColor.blueColor();
//添加到视图上
self.view.addSubview(but1);
//添加一个Item Item使用系统图标
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:
//进入下一页再次压栈
//创建一个试图控制器
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="我给你笑一个吧