UI一揽子计划 8 (UINavigationController 、界面通信 、NSTimer 、NSUserDefaults)
// 创建一个导航控制器
// 创建一个控制器作为根控制器 去管理
RootViewController *rootVC = [[RootViewController alloc]init];
UINavigationController *navC = [[UINavigationController alloc]initWithRootViewController:rootVC];
[rootVC release];
// 把导航控制器作为window的根控制器
self.window.rootViewController = navC;
[super viewDidLoad];
self.view.backgroundColor = [UIColor greenColor];
// 创建一个按钮 进入下一个页面
UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];
button.frame = CGRectMake(100, 100, 100, 100);
[self.view addSubview:button];
button.backgroundColor = [UIColor redColor];
[button setTitle:@"2" forState:(UIControlStateNormal)];
[button release];
// 添加方法 进入下一个界面
[button addTarget:self action:@selector(actionButton:) forControlEvents:(UIControlEventTouchDragInside)];
- (void)actionButton:(UIButton *)button
{
// 创建下一个界面的
SecondViewController *secondVC = [[SecondViewController alloc]init];
// ViewControllers 是导航控制器管理的那一组控制器 所有被管理的控制器们都存放在这个数组中
// NSLog(@"%@", self.navigationController.viewControllers);
// 跳转去下一个页面 push
[self.navigationController pushViewController:secondVC animated:YES];
[secondVC release];
// NSLog(@"%@", self.navigationController.viewControllers);
// 栈顶的控制器
// 正显示的控制器
NSLog(@"栈顶%@", self.navigationController.topViewController);
[self.navigationController popViewControllerAnimated:YES];
}
- (void)actionSecondButton:(UIButton *)button
{
// 返回根界面
[self.navigationController popToRootViewControllerAnimated:YES];
}
- (void)actionThirdButton:(UIButton *)button
{
// 返回到指定界面
// 需要从被管理的数组中 把要返回的取出来
NSArray *viewControllers = self.navigationController.viewControllers;
SecondViewController *sec = viewControllers[1];
[self.navigationController popToViewController:sec animated:YES];
// 或者下面的
状态栏高 20
bar 高 44
*/
self.view.backgroundColor = [UIColor redColor];
self.navigationItem.title = @"首页";
// 创建一个UIView出来给titleView 有了View 想往上面加什么都随意
//UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, 44)];
// view.backgroundColor = [UIColor whiteColor];
//self.navigationItem.titleView = view;
// 用系统样式初始化一个UIBarButtonItem
UIBarButtonItem *leftButton = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCamera target:self action:@selector(actionLeftBarButtonItem:)];
self.navigationItem.leftBarButtonItem = leftButton;
[leftButton release];
// 用标题的初始化方法 初始化右面的按钮
UIBarButtonItem *rightBarButton = [[UIBarButtonItem alloc]initWithTitle:@"确 定" style:(UIBarButtonItemStylePlain) target:self action:@selector(actionRightBarButtonItem:)];
self.navigationItem.rightBarButtonItem = rightBarButton;
// 用图片初始化UIBarButtonItem
UIBarButtonItem *imageBarButton = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"left"] style:(UIBarButtonItemStylePlain) target:self action:@selector(actionImageBarButton:)];
self.navigationItem.rightBarButtonItem = imageBarButton;
[imageBarButton release];
// 设置一下Bar 的颜色及图片
// [self.navigationController.navigationBar setBarTintColor:[UIColor grayColor]];
// 高44 的把 导航条遮住了,漏出了状态栏
// 高64 的把 导航栏和状态栏都充满
// [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"32064"] forBarMetrics:(UIBarMetricsDefault)];
// 重要的属性
// 从7.0 以后 导航条默认是半透明的 如果半透明 从屏幕左上角开始计算frame
// 如果设置成不透明的 从导航条的底部开始计算frame
// 透明度的设置
self.navigationController.navigationBar.translucent = NO;
//
// Do any additional setup after loading the view.
}
- (void)actionLeftBarButtonItem:(UIBarButtonItem *)barButtonItem
{
NSLog(@"启动照相机");
}
- (void)actionRightBarButtonItem:(UIBarButtonItem *)barButtonItem
{
NSLog(@"我是右面的ooo");
}
- (void)actionImageBarButton:(UIBarButtonItem *)barButtonItem
{
1. 点击跳转方法的时候传值
2. 要传递的是什么? 传递的是数据不是控件
UITextField *textField = (UITextField *)[self.view viewWithTag:888];
NSString *string = textField.text;
// 要有一个属性来接收这个数据
SecondViewController *second = [[SecondViewController alloc]init];
- (void)changeTextFieldString:(NSString *)string;
@end
@interface SecondViewController : UIViewController
@property (nonatomic,retain)NSString *string;
{
SecondViewController *second = [[SecondViewController alloc]init];
// 设置代理
UITextField *textField = (UITextField *)[self.view viewWithTag:888];
textField.text = string;
// 要拿到要传递的数据
UITextField *textField = (UITextField *)[self.view viewWithTag:888];
NSString *string = textField.text;
// 要有一个属性来接收这个数据
SecondViewController *second = [[SecondViewController alloc]init];
second.string = string;
// 设置代理
second.delegate = self;
[self.navigationController pushViewController:second animated:YES];
{
UITextField *textField = (UITextField *)[self.view viewWithTag:999];
[_delegate changeTextFieldString:textField.text];
[self.navigationController popToRootViewControllerAnimated:YES];
// 一般只用这个来存储 例如: 账号/密码/设备ID... ...
// 单例, 目前就叫初始化一个对象就行
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
// 保存
[userDefaults setObject:@"尚亚雷" forKey:@"shang"];
// 同步数据
[userDefaults synchronize];
// 打印沙盒路径
NSLog(@"%@", NSHomeDirectory());
/*
/Users/lanou3g/Library/Developer/CoreSimulator/Devices/F4C0035C-BFC9-4B9A-95D1-59CE94B63E35/data/Containers/Data/Application/1F290708-5666-45D8-9222-AFAD1EC03E16
*/
/*
// 取出沙盒里面保存的数据
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSString *string = [userDefaults objectForKey:@"shang"];
NSLog(@"%@", string);
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
NSString *string = [userDefaults objectForKey:@"shang"];
UI一揽子计划 8 (UINavigationController 、界面通信 、NSTimer 、NSUserDefaults)相关推荐
- UI一揽子计划 17 (image的异步加载、KVO观察者模式、KVO进行豆瓣列表界面图片的异步加载)
把下载图片的封装起来 ImageDownloader.h #import <Foundation/Foundation.h> @protocol ImageDownloaderDel ...
- UI一揽子计划 20 (豆瓣实战之图片缓存 、豆瓣实战之详情界面(自适应行高) 、豆瓣实战之登陆注销、刘新林分享之UIAlertController)
一.图片缓存 ActivityModel.m 如果数据加载完毕就将图片放到缓存中. #pragma mark -- imageDownLoader 代理方法 // 成功返回data - (void) ...
- UI一揽子计划 1 (UIView UILabel)
第一天 1.UIView ·建立一个空模板后,首先将ARC模式关闭,因为iOS采用MRC模式,即手动管理内存. ·重写dealloc方法. - (void)dealloc { [_window rel ...
- UI一揽子计划 24 (MVC、通知、)
一.MVC Model - View - Controller 即 模型 - 视图 - 控制器 Modle (模型) 存储 处理数据 为应用程序提供数据. View (视图)展示用户界面视图,提供 ...
- UI一揽子计划 12 (模态ViewController、单例、通讯录实战、)
一.模态ViewController 程序中切换⻚面,可以使⽤用UINavigationController.通过导航功能实现⻚面切 换. 某种情况下,可以使⽤视图控制器的一对⽅法实现切换⻚面 1.p ...
- UI一揽子计划 22 (多线程概述、NSThread、NSOperationQueue 、GCD、多线程管理)
一.多进程概述: 进程: 一个正在运行的程序 叫做一个进程 多进程: 多个程序正在运行 叫做多线程 线程: 一个进程 都会有一个或多个线程 如果只有一个 叫做主线程 主线程负 ...
- UI一揽子计划 11 (自定义UITableViewCell、Cell 的自适应高度)
一. 自定义UITableViewCell 在日常的编程中,系统提供的几种Cell 样式 往往不能满足我们的需求.所以需要我们给它进行自定义样式. 自定义Cell 就是创建一个UITableViewC ...
- UI一揽子计划 6 (UIControl、UISegmentedControl、UIImageView插入数组图片、UISlider)
一 UIControl 是所有控制类控件的基类. · 比如UIButton UISlider UISegmentedControl 等只要跟控件有关系的都继承于UIControl类 ...
- UI一揽子计划 10 (UITableView 中cell 的编辑, 增加, 删除、UITableViewController 、)
一.tableView的编辑 tableView 编辑的步骤: * 1. 让tableView成为可编辑状态 编辑按钮触发方法 * -1. 激活编辑状态 - (void)r ...
最新文章
- 【ruby项目,语言提交检查(一)】怎样高速学习ruby ?
- 分布式缓存技术memcached学习(一)——linux环境下编译memcahed
- macbook下载苹果版Photoshop cc2019 for mac
- 多线程:interrupted、isinterrupted区别
- sql is null优化_你不会还在用这8个错误的SQL写法吧?
- TCP/IP TIME_WAIT状态原理
- [html] 通过设置表单的target=“_blank“来下载文件会被浏览器拦截吗?如何解决?
- php 异常错误信息用处,关于PHP中异常错误的处理详细介绍
- android 参数 attrs.xml,使用attrs.xml自定义属性
- 年薪35W+ 的程序员看过来!百万架构师第3期招生
- Ubuntu 挂载新磁盘
- iptables oracle策略,利用iptables防火墙保护Oracle数据库
- jpush推送格式 swift_Swift - JPush极光推送的使用6(定时推送通知)
- add script param in pycharm
- open cv+C++错误及经验总结(五)
- phpstorm内网远程debug
- 最新中国大陆行政区域划分
- VC的一些实用技巧和注意事项。
- 计算机右键管理提示没有关联应用,win10系统计算机右键管理提示没有与之关联的程序的解决方法...
- CPAN | 配置阿里源