UI1_ViewController视图切换及Appdelegate
//
// ThirdViewController.h
// UI1_ViewController视图切换及Appdelegate
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @interface ThirdViewController : UIViewController @end //
// ThirdViewController.m
// UI1_ViewController视图切换及Appdelegate
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "ThirdViewController.h" @interface ThirdViewController () @end @implementation ThirdViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor greenColor]; UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(20, 200, self.view.frame.size.width-40, 50);
btn.backgroundColor = [UIColor whiteColor];
[btn setTitle:@"切换视图到SecondView" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];
btn.tag = 100;
[self.view addSubview:btn];
} - (void)btnClicked
{
[self dismissViewControllerAnimated:YES completion:nil];
} - (void)didReceiveMemoryWarning {
[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
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end //
// SecondViewController.h
// UI1_ViewController视图切换及Appdelegate
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @interface SecondViewController : UIViewController @end //
// SecondViewController.m
// UI1_ViewController视图切换及Appdelegate
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "SecondViewController.h"
#import "AppDelegate.h"
#import "ThirdViewController.h" @interface SecondViewController () @end @implementation SecondViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor redColor];
UIApplication *app = [UIApplication sharedApplication];
AppDelegate *delegate = app.delegate;
[delegate.shareArray addObject:@"three"];
NSLog(@"shareArray = %@", delegate.shareArray); UIButton *btn1 = [UIButton buttonWithType:UIButtonTypeSystem];
btn1.frame = CGRectMake(20, 200, self.view.frame.size.width-40, 50);
btn1.backgroundColor = [UIColor whiteColor];
[btn1 setTitle:@"切换视图到FirstView" forState:UIControlStateNormal];
[btn1 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
btn1.tag = 100;
[self.view addSubview:btn1]; UIButton *btn2 = [UIButton buttonWithType:UIButtonTypeSystem];
btn2.frame = CGRectMake(20, 300, self.view.frame.size.width-40, 50);
btn2.tag = 200;
btn2.backgroundColor = [UIColor whiteColor];
[btn2 setTitle:@"切换视图到ThirdView" forState:UIControlStateNormal];
[btn2 addTarget:self action:@selector(btnClicked:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn2]; } - (void)btnClicked:(UIButton *)btn
{
if (btn.tag==100) {
[self dismissViewControllerAnimated:YES completion:nil];
}
else if(btn.tag ==200)
{
ThirdViewController *tvc = [[ThirdViewController alloc] init];
tvc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:tvc animated:YES completion:nil];
}
} - (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSLog(@"SecondView 将要显示");
} - (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
NSLog(@"SecondView 已经显示");
} - (void)didReceiveMemoryWarning {
[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
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/ @end
//
// AppDelegate.h
// UI1_ViewController视图切换及Appdelegate
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h>
#import <CoreData/CoreData.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (retain, nonatomic)NSMutableArray *shareArray; @property (strong, nonatomic) UIWindow *window; @property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext;
@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel;
@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator; - (void)saveContext;
- (NSURL *)applicationDocumentsDirectory; @end //
// AppDelegate.m
// UI1_ViewController视图切换及Appdelegate传值
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "AppDelegate.h" @interface AppDelegate () @end @implementation AppDelegate - (instancetype)init
{
self = [super init];
if (self) {
self.shareArray = [NSMutableArray array];
}
return self;
} - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
//通过单例方法获取当前应用程序唯一对象
UIApplication *app=[UIApplication sharedApplication];
//获取当前应用程序的代理对象
AppDelegate *delegate = app.delegate; [delegate.shareArray addObject:@"one"];
NSLog(@"shareArray = %@", delegate.shareArray); return YES;
}
//
// ViewController.h
// UI1_ViewController视图切换及Appdelegate
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <UIKit/UIKit.h> @interface ViewController : UIViewController @end //
// ViewController.m
// UI1_ViewController视图切换及Appdelegate
//
// Created by zhangxueming on 15/7/3.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "ViewController.h"
#import "AppDelegate.h"
#import "SecondViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIApplication *app = [UIApplication sharedApplication];
AppDelegate *delegate = app.delegate;
[delegate.shareArray addObject:@"two"];
NSLog(@"shareArray = %@", delegate.shareArray); // UIButton *btn = [UIButton buttonWithType:UIButtonTypeSystem];
btn.frame = CGRectMake(20, 100, self.view.frame.size.width-40, 50);
[btn setTitle:@"切换视图到SecondView" forState:UIControlStateNormal];
btn.backgroundColor = [UIColor whiteColor];
[btn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
self.view.backgroundColor = [UIColor cyanColor];
} - (void)btnClicked
{
SecondViewController *svc = [[SecondViewController alloc] init];
//设置视图切换模式
svc.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
//
[self presentViewController:svc animated:YES completion:nil];
} - (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
NSLog(@"FirstView 将要消失");
} - (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
NSLog(@"FirstView 已经消失");
} - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end
UI1_ViewController视图切换及Appdelegate的更多相关文章
- iOS开发系列--视图切换
概述 在iOS开发中视图的切换是很频繁的,独立的视图应用在实际开发过程中并不常见,除非你的应用足够简单.在iOS开发中常用的视图切换有三种,今天我们将一一介绍: UITabBarController ...
- UI2_视图切换ViewController
// // SubViewController.h // UI2_视图切换 // // Created by zhangxueming on 15/7/3. // Copyright (c) 2015 ...
- Tabbar视图切换,返回上一视图,添加item
前面有一篇博文iOS学习之Tab Bar的使用和视图切换 这是在AppDelegate里使用Tabbar,这样的程序打开就是TabbarView了,有时候我们需要给程序做一些帮助页面,或者登录页面,之 ...
- IPhone多视图切换
处理IPhone多个view切换是我们常遇到的问题,接下来有个比较实用的方法: 而且还附有创建空项目,内存告急处理和动画效果的实现! 具体步骤: 1.创建一个空的项目,然后添加一个ViewContro ...
- iOS:删除storyBoard,纯代码实现UITabBarController的视图切换功能
storyboard是一个很强大的编写代码的辅助工具,可以帮助布局多个视图之间的联系,既直观又能减少代码量:但是,作为一个程序员,在不使用storyboard的情况下,纯代码编写是必须的技能. 下面就 ...
- pushViewController addSubview presentModalViewController视图切换
1.pushViewController和popViewController来进行视图切换,首先要确保根视图是NavigationController,不然是不可以用的, pushViewContro ...
- IOS 视图切换动画
我在网上找到的这个小方法,被我举一反三使用的屡试不爽.比如用在,当视图需要执行某一方法跳转到新的一个UIView上,从底层渐变浮到最上层.就是一个不错的视觉效果或者当需要类似keyboard的效果从底 ...
- UI3_视图切换
// // ViewController.m // UI3_视图切换 // // Created by zhangxueming on 15/7/3. // Copyright (c) 2015年 z ...
- UI2_视图切换
// // ViewController.m // UI2_视图切换 // // Created by zhangxueming on 15/7/1. // Copyright (c) 2015年 z ...
随机推荐
- js密码强度
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Winform模拟post请求和get请求登录网站
引言 最近有朋友问如何用winform模拟post请求,然后登录网站,稍微想了一下,大致就是对http报文的相关信息的封装,然后请求网站登录地址的样子.发现自己的博客中对这部分只是也没总结,就借着这股 ...
- 【JavaScript】javascript常用的东西
DOM编程.AJAX编程.异步编程(nodejs会涉及的相对多一点,事件.ajax) 函数.函数表达式.回调函数是基础. JavaScript的函数是一个核心. 回调函数有点类似于Android中的回 ...
- iOS开发——UI篇Swift篇&UIScrollView
UIScrollView //返回按钮事件 @IBAction func backButtonClick() { self.navigationController?.popViewControlle ...
- Linux内核高端内存 转
Linux内核地址映射模型x86 CPU采用了段页式地址映射模型.进程代码中的地址为逻辑地址,经过段页式地址映射后,才真正访问物理内存. 段页式机制如下图. Linux内核地址空间划分 通 ...
- D2 前端技术论坛总结(上)
得幸获得D2前端技术论坛门票一张,今天就去了,公司还给批假了(有可能不会算做请假,哈哈). 早上8点50出门,骑个小毛驴,大概9点30分左右,到了阿里巴巴西溪园区,很多人,进去的门口有专人接待,看D2 ...
- IDEA 升级14.1提示org/hibernate/build/gradle/publish/auth/maven/AuthenticationManager:Unsupported major.minor version 51.0
在看到“Unsupported major.minor version 51.0”这样的错误描述时,就基本可以肯定是jdk版本不正确导致.但是提示的类非业务系统,而是来自IDEA.因此去其官网检索了下 ...
- Python编码相关文章推荐
Table of Contents 1. 分享 分享 python2里面编码对很多人来说是个很头疼的问题,今天分享一篇编码相关的文章,是前几天读到的相比于大部分解释编码问题的一知半解模糊不清,这篇写得 ...
- 1.7.2 Velocity Search UI
1. Velocity Search UI solr包含了一个简单的搜索UI界面,是基于VelocityResponseWrite(也被叫做 Solritas)的.这里演示了几个有用的功能,如搜索,分 ...
- How to make remote key fob for 2002 BMW 3 series
Here share with you on how to make remote key fob for 2002 BMW 3 series: Method 1: 1. Working within ...