2019独角兽企业重金招聘Python工程师标准>>>

//
//  AppDelegate.h
//  视图的层次关系
//
//  Created by on 14-12-17.
//  Copyright (c) 2014年 apple. All rights reserved.
//#import <UIKit/UIKit.h>
#import <CoreData/CoreData.h>@interface AppDelegate : UIResponder <UIApplicationDelegate> {UIView *view1;UIView *view2;UIView *view3;
}@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
//  视图的层次关系
//
//  Created by on 14-12-17.
//  Copyright (c) 2014年 apple. All rights reserved.
//#import "AppDelegate.h"@interface AppDelegate ()@end@implementation AppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {// Override point for customization after application launch.self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];self.window.backgroundColor = [UIColor whiteColor];[self.window makeKeyAndVisible];view1 = [[UIView alloc] initWithFrame:CGRectMake(60, 100, 200, 100)];view1.backgroundColor = [UIColor redColor];[self.window addSubview:view1];view2 = [[UIView alloc] initWithFrame:CGRectMake(60, 170, 200, 100)];view2.backgroundColor = [UIColor yellowColor];[self.window addSubview:view2];//    view1和view2都是加在UIWindow上的,所以他们的super view都是UIWindow
//    NSLog(@"view1 super view: %@", [view1 superview]);
//    NSLog(@"view2 super view: %@", [view2 superview]);view3 = [[UIView alloc] initWithFrame:CGRectMake(60,100, 200, 50)];view3.backgroundColor = [UIColor blueColor];[self.window addSubview:view3];//    这次是将view3加在了view1的上面,所以view3的super view 是view1
//    NSLog(@"view1 super view: %@", [view1 superview]);
//    NSLog(@"view3 super view: %@", [view3 superview]);UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];button1.frame = CGRectMake(90, 300, 140, 35);[button1 setTitle:@"使view1至于顶层" forState:UIControlStateNormal];[button1 addTarget:self action:@selector(changeView1) forControlEvents:UIControlEventTouchUpInside];[self.window addSubview:button1];UIButton *button2 = [UIButton buttonWithType:UIButtonTypeRoundedRect];button2.frame = CGRectMake(90, 340, 140, 35);[button2 setTitle:@"使view2至于顶层" forState:UIControlStateNormal];[button2 addTarget:self action:@selector(changeView2) forControlEvents:UIControlEventTouchUpInside];[self.window addSubview:button2];UIButton *button3 = [UIButton buttonWithType:UIButtonTypeRoundedRect];button3.frame = CGRectMake(90, 380, 140, 35);[button3 setTitle:@"使view3至于顶层" forState:UIControlStateNormal];[button3 addTarget:self action:@selector(changeView3) forControlEvents:UIControlEventTouchUpInside];[self.window addSubview:button3];return YES;
}- (void)changeView1 {[self.window bringSubviewToFront:view1];
}- (void)changeView2 {[self.window bringSubviewToFront:view2];
}- (void)changeView3 {[self.window bringSubviewToFront:view3];
}- (void)applicationWillResignActive:(UIApplication *)application {// 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.
}- (void)applicationDidEnterBackground:(UIApplication *)application {// 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.
}- (void)applicationWillEnterForeground:(UIApplication *)application {// 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.
}- (void)applicationDidBecomeActive:(UIApplication *)application {// 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.
}- (void)applicationWillTerminate:(UIApplication *)application {// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.// Saves changes in the application's managed object context before the application terminates.[self saveContext];
}#pragma mark - Core Data stack@synthesize managedObjectContext = _managedObjectContext;
@synthesize managedObjectModel = _managedObjectModel;
@synthesize persistentStoreCoordinator = _persistentStoreCoordinator;- (NSURL *)applicationDocumentsDirectory {// The directory the application uses to store the Core Data store file. This code uses a directory named "apple._______" in the application's documents directory.return [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
}- (NSManagedObjectModel *)managedObjectModel {// The managed object model for the application. It is a fatal error for the application not to be able to find and load its model.if (_managedObjectModel != nil) {return _managedObjectModel;}NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"_______" withExtension:@"momd"];_managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL];return _managedObjectModel;
}- (NSPersistentStoreCoordinator *)persistentStoreCoordinator {// The persistent store coordinator for the application. This implementation creates and return a coordinator, having added the store for the application to it.if (_persistentStoreCoordinator != nil) {return _persistentStoreCoordinator;}// Create the coordinator and store_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"_______.sqlite"];NSError *error = nil;NSString *failureReason = @"There was an error creating or loading the application's saved data.";if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:nil error:&error]) {// Report any error we got.NSMutableDictionary *dict = [NSMutableDictionary dictionary];dict[NSLocalizedDescriptionKey] = @"Failed to initialize the application's saved data";dict[NSLocalizedFailureReasonErrorKey] = failureReason;dict[NSUnderlyingErrorKey] = error;error = [NSError errorWithDomain:@"YOUR_ERROR_DOMAIN" code:9999 userInfo:dict];// Replace this with code to handle the error appropriately.// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.NSLog(@"Unresolved error %@, %@", error, [error userInfo]);abort();}return _persistentStoreCoordinator;
}- (NSManagedObjectContext *)managedObjectContext {// Returns the managed object context for the application (which is already bound to the persistent store coordinator for the application.)if (_managedObjectContext != nil) {return _managedObjectContext;}NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator];if (!coordinator) {return nil;}_managedObjectContext = [[NSManagedObjectContext alloc] init];[_managedObjectContext setPersistentStoreCoordinator:coordinator];return _managedObjectContext;
}#pragma mark - Core Data Saving support- (void)saveContext {NSManagedObjectContext *managedObjectContext = self.managedObjectContext;if (managedObjectContext != nil) {NSError *error = nil;if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) {// Replace this implementation with code to handle the error appropriately.// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.NSLog(@"Unresolved error %@, %@", error, [error userInfo]);abort();}}
}@end

转载于:https://my.oschina.net/are1OfBlog/blog/364563

UI代码练习-视图的层次关系相关推荐

  1. 2.3 视图的层次关系

    UIView 层次结构是"视图树" 视图是容器 父视图 superview  子视图 subview 一个视图可以嵌入多个subview 但是只有一个superview 调用add ...

  2. python语言用什么来表明每行代码的层次关系_《计算机二级Python语言程序设计考试》第2章: Python语言基本语法元素...

    注明:本系列课程专为全国计算机等级考试二级 Python 语言程序设计考试服务 目录 考纲考点 程序的基本语法元素:程序的格式框架.缩进.注释.变量.命名.保留字.数据类型.赋值语句.引用 基本输入输 ...

  3. python语言用什么来表明每行代码的层次关系_2021年尔雅通识课《切削原理与刀具》课后习题答案...

    2021年尔雅通识课<切削原理与刀具>课后习题答案 二战后南海局势比较稳定的原因不包括() 答:冷战后相当长时间内,中美战略关系极不稳定 日本是一个多地震国家,主要因为它位于海岛上. 答: ...

  4. python用缩进来标明代码的层次关系_8-1-Python设计案例.pptx

    第8章 Python程序设计基础 学习导图 学习内容 Python 简 介 Python 环境搭建 1. 认识Python 学习内容 Python是一种解释型的.面向对象的.交互式的高级程序设计语言. ...

  5. python用缩进来标明代码的层次关系_Python第二弹python基础

    标签: python基础 1.语句和语法 #号:表示之后的字符串为python注释 \n换行是标准的分隔符 \(反斜线)继续上一行 ;(分号)将两个语句链接在一行中,允许将多个语句写在同一行上,语句之 ...

  6. 剖析CWE视图的层次定义和解析方式

    摘要:CWE做为软件缺陷分类的重要标准, 对安全研究.安全标准.缺陷管理起了重要的纽带作用.CWE通过编号的类型(类缺陷.基础缺陷和变种缺陷等)形成了多层次的缺陷类型划分体系.本文进一步剖析了CWE视 ...

  7. 使用TensorFlow搭建智能开发系统,自动生成App UI代码

    本文转自微信号EAWorld.扫描下方二维码,关注成功后,回复"普元方法+",将会获得热门课堂免费学习机会! 本文目录: 一.我们的现状与期望 二.我们的初级探索及建议 三.智能开 ...

  8. UI界面:手写UI代码或者使用xib和StoryBoard制作UI界面的区别和分析

    UI: Code vs Xibs vs StoryBoard 最近接触了几个刚入门的iOS学习者,他们之中存在一个普遍和困惑和疑问,就是应该如何制作UI界面.iOS应用是非常重视用户体验的,可以说绝大 ...

  9. 如何构建一个理想UI代码表达的自动化工具?

    作者:闲鱼技术-吉丰 基于设计师产出的 Sketch,甚至是一张 PNG,就能自动生成高可维护可扩展的 UI 代码,质量堪比一位资深前端工程师, 一定是一件让整个大前端领域都为之尖叫的事情. 出于这样 ...

最新文章

  1. npm你不知道的8个快捷键
  2. ubuntu codeblocks 设置用默认的gnome-terminal进行调试
  3. django文档_如何在django官方文档中快速找到需要的内容
  4. 可编程智能小车,100种玩法,从3岁玩到15岁,培养孩子“最强大脑”
  5. 服务器zip解压php,服务器端解压缩zip的脚本
  6. 继承中的复制构造、赋值、析构、重载
  7. python樱花树代码_【推荐】手把手教你如何用Python画一棵漂亮樱花树含源码
  8. RADIO廉价冗余阵列radio0 dadio1 radio10/01 radio5 radio6
  9. 南昌大学计算机接收调剂的条件,关于2018年河南昌大学学硕士研究生接收调剂程序及要求的须知详情...
  10. python print 3位小数_python 这样 print 才够骚啊 (3)
  11. arcmap中有火星坐标码_GIS转换之火星坐标系转换
  12. 一文带你读懂 Java Agent 内存马
  13. linux mysqldump 备份所有数据库,mysqldump导出所有数据库
  14. 有道云笔记迁移至语雀终极解决方案
  15. WPF窗口属性设置(无边框,任务栏隐藏图标,任务管理器应用程序隐藏图标)
  16. MySQL服务无法启动,服务没有报告任何错误--解决方案
  17. 绵阳python培训_绵的繁体字怎么写_绵字有几笔、五行属性-幸运吧起名网
  18. 徐荣谦《养好脾和肺 宝宝不积食不咳嗽长大个》【01】小儿常见病
  19. 危化品爆炸场景下的应急通信系统解决方案
  20. 树莓派基础实验11:U型光电传感器实验

热门文章

  1. c++ map iterator 获取key_JAVA | Map集合使用详解
  2. linux文件操作相关函数
  3. 数据可视化【四】Bar Chart
  4. 进程间关系和守护进程
  5. python浅蓝色对应的代码_浅蓝色Python模块不在m上工作
  6. 微信小程序之视图容器(swiper)组件创建轮播图
  7. 用php生成HTML文件的类
  8. Python 操作 MySQL 的5种方式(转)
  9. C#中全局处理异常方式
  10. 总结verilog产生随机数的$random和seed