UI_NavigationController
来源:互联网 发布:apache ab get参数 编辑:程序博客网 时间:2024/06/07 12:22
#import "AppDelegate.h"
#import "MainViewController.h"
@interface AppDelegate ()
@end
@implementation AppDelegate
- (void)dealloc
{
[_windowrelease];
[superdealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColorwhiteColor];
[self.windowmakeKeyAndVisible];
[_windowrelease];
MainViewController *mainVC = [[MainViewControlleralloc] init];
//导航控制器的使用
//创建导航控制器的时候指定一个栈底控制器(rootVC)
UINavigationController *navi = [[UINavigationControlleralloc] initWithRootViewController:mainVC];
//把导航控制器指定为window的根视图控制器
self.window.rootViewController = navi;
[mainVCrelease];
[navirelease];
return YES;
}
#import "MainViewController.h"
#import "SecondViewController.h"
@interface MainViewController ()
@end
@implementation MainViewController
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view.
self.title =@"第一页";
// 设置NavigationBar 导航栏
//导航栏对每个导航控制器都是唯一的
// 获取导航栏对象
// 1. 改变导航栏的颜色
// self.navigationController.navigationBar.barTintColor = [UIColor greenColor];
// 2.改变导航栏的半透明度效果,会相应的改变VC的view的坐标系起点
// self.navigationController.navigationBar.translucent = YES;
// 3. 隐藏导航栏
// self.navigationController.navigationBarHidden = YES;
// navigationItem
//保存按钮信息的一个类,每个VC都有一个这个类的属性,用来保存显示在导航栏上的按钮信息
// 右侧的按钮 right
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItemalloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrashtarget:selfaction:@selector(barButtonAction:)]autorelease];
// 中间的自定义视图 titleView
// UISegmentedControl *seg = [[UISegmentedControl alloc] initWithItems:@[@"1",@"2"]];
// self.navigationItem.titleView = seg;
// [seg release];
self.view.backgroundColor = [UIColorredColor];
UIButton *button = [UIButtonbuttonWithType:UIButtonTypeSystem];
button.frame =CGRectMake(20,120, 335, 40);
button.backgroundColor = [UIColoryellowColor];
[button setTitle:@"推出第二页"forState:UIControlStateNormal];
[button addTarget:selfaction:@selector(buttonAction:)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:button];
}
- (void)barButtonAction:(UIBarButtonItem *)item
{
NSLog(@"导航栏按钮");
}
- (void)buttonAction:(UIButton *)btn
{
NSLog(@"点击");
// 使用导航控制器push一个新的VC
// (约定VC代表视图控制器(viewController))
// 1.创建一个新的VC对象
SecondViewController *secondVC = [[SecondViewControlleralloc] init];
// 2.使用导航控制器push新的VC
[self.navigationController pushViewController:secondVC animated:YES];
// 3.内存管理
[secondVCrelease];
}
#import "ForthViewController.h"
@interface ForthViewController ()
@end
@implementation ForthViewController
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColorpurpleColor];
UIButton *button = [UIButtonbuttonWithType:UIButtonTypeSystem];
button.frame =CGRectMake(20,120, 335, 40);
button.backgroundColor = [UIColoryellowColor];
[button setTitle:@"返回"forState:UIControlStateNormal];
[button addTarget:selfaction:@selector(buttonAction:)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:button];
}
- (void)buttonAction:(UIButton *)btn
{
// 使用导航控制器出栈(pop)
// 1.返回首页
// [self.navigationController popToRootViewControllerAnimated:YES];
// 2. 返回上一页
// [self.navigationController popViewControllerAnimated:YES];
// 3.返回栈里面的某一页
UIViewController *vc1 = [self.navigationController.viewControllersobjectAtIndex:1];
[self.navigationControllerpopToViewController:vc1 animated:YES];
}
- UI_NavigationController
- MFC 车牌识别 小学期作业 part3
- HDU 5288 OO’s Sequence (2015 MUT#1 数学+质因子分解)
- iOS工程适配64-bit经验分享
- android 学习笔记 数据存储到文件中
- 鼓励自己成为一名合格程序设计师
- UI_NavigationController
- STL vector的使用(三)遍历
- json
- 封装类之CSplashWnd(应用程序的启动画面)
- 基于栈的一些操作
- codeforces 498C C. Array and Operations(最大流+数论)
- 在运行期通过反射了解JVM内部机制
- MFC 车牌识别 小学期作业 part4
- Linux学习记录(5)Vi编辑器基本使用