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

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

//
//  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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/401005.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

arthas学习图文记录

&#x1f680; 优质资源分享 &#x1f680; 学习路线指引&#xff08;点击解锁&#xff09;知识定位人群定位&#x1f9e1; Python实战微信订餐小程序 &#x1f9e1;进阶级本课程是python flask微信小程序的完美结合&#xff0c;从项目搭建到腾讯云部署上线&#xff0c;打造一…

利用矩阵的n次方求图的连通性

设A&#xff08;n x n&#xff09;为一个图的邻接矩阵&#xff0c;则a(i,j)表示两个点之间是否连通&#xff08;1&#xff1a;连通&#xff0c;0&#xff1a;不连通&#xff09;。那么A的k次方中的每一个a&#xff08;i&#xff0c;j&#xff09;表示点i和j之间长度为k的路的条…

使用HBuilder新建项目

依次点击文件→新建→选择Web项目(按下CtrlN,W可以触发快速新建(MacOS请使用CommandN,然后左键点击Web项目)) 如上图&#xff0c;请在A处填写新建项目的名称&#xff0c;B处填写(或选择)项目保存路径(更改此路径HBuilder会记录&#xff0c;下次默认使用更改后的路径)&#xff0…

iOS应用开发视频教程笔记(二)My First iOS App

这课主要是以一个计算器一个用为例子&#xff0c;教你怎么使用XCode&#xff0c;如何使用MVC设计模式创建应用。 (1)新建一个single view application模版的应用 打开xcode并点击“创建一个新xcode项目”&#xff0c;进入项目创建界面&#xff0c;这个界面让我们为应用选择一个…

牛顿迭代法(Newton#39;s Method)

牛顿迭代法&#xff08;简称牛顿法&#xff09;由英国著名的数学家牛顿爵士最早提出。可是&#xff0c;这一方法在牛顿生前并未公开发表&#xff08;讨厌的数学家们还是鼓捣出来了&#xff09;牛顿法的作用是使用迭代的方法来求解函数方程的根。简单地说&#xff0c;牛顿法就是…

【深入理解计算机系统CSAPP】第六章 存储器层次结构

&#x1f680; 优质资源分享 &#x1f680; 学习路线指引&#xff08;点击解锁&#xff09;知识定位人群定位&#x1f9e1; Python实战微信订餐小程序 &#x1f9e1;进阶级本课程是python flask微信小程序的完美结合&#xff0c;从项目搭建到腾讯云部署上线&#xff0c;打造一…

【转】无刷新验证用户名可用性

在用户注册时&#xff0c;我们经常需要检查用户名是否存在&#xff0c;本文就是实现无刷新验证用户名 打开开发环境VS 2005,新建项目(或打开现有项目),新建一个Web窗体,命名为 Default.aspx 代码如下&#xff1a; View Code <% Page Language"C#" AutoEventWireu…

Python数据分析--Numpy常用函数介绍(2)

&#x1f680; 优质资源分享 &#x1f680; 学习路线指引&#xff08;点击解锁&#xff09;知识定位人群定位&#x1f9e1; Python实战微信订餐小程序 &#x1f9e1;进阶级本课程是python flask微信小程序的完美结合&#xff0c;从项目搭建到腾讯云部署上线&#xff0c;打造一…

bzoj3224: Tyvj 1728 普通平衡树(打个splay暖暖手)

&#xff08;其实今天好热啊&#xff1f; 题目大意&#xff1a;插入&#xff0c;删除&#xff0c;k小&#xff0c;前驱后继&#xff0c;数的排名。 splay和treap裸题...过几天补个treap的 splay: #include<iostream> #include<cstdlib> #include<cstring> #i…

手机相机自动识别语音提示

技术背景&#xff1a; 时下流行的手机拍照功能越来越多&#xff0c;在众多的手机拍照过程中&#xff0c;我们只在于手机拍照的效果和风景是否美好&#xff0c;甚至拿着手机自我狂拍&#xff0c;留下美好的记忆和回忆。 有时候根据手机相机的已有技术功能随便一设置就能拍到理想…

c# Invoke和BeginInvoke 区别

转自http://www.cnblogs.com/c2303191/articles/826571.html Control的Invoke和BeginInvoke是相对于支线线程&#xff08;因为一般在支线线程中调用&#xff0c;用来更新主线程ui&#xff09;Invoke立即插入主线程中执行&#xff0c;而BeginInvoke 要等主线程结束才执行 近日&a…

04 Springboot 格式化LocalDateTime

&#x1f680; 优质资源分享 &#x1f680; 学习路线指引&#xff08;点击解锁&#xff09;知识定位人群定位&#x1f9e1; Python实战微信订餐小程序 &#x1f9e1;进阶级本课程是python flask微信小程序的完美结合&#xff0c;从项目搭建到腾讯云部署上线&#xff0c;打造一…

DNN使用非80端口和总是跳转到http://localhost问题的解决

2019独角兽企业重金招聘Python工程师标准>>> 我试图在一台服务器上安装一个DNN网站时&#xff0c;遇到了一些问题。问题一&#xff1a;遇到的第一个问题就是网站总是自动导向到localhost。不管我怎么试&#xff0c;只要我输入http://domain.com/dnn&#xff0c;总是…

Jmter操作数据库

1、导入jdbc的jar包&#xff0c;因为jmeter本身不能直接连接mysql&#xff0c;所以需要导入第三方的jar包&#xff0c;来连接mysql&#xff0c;如下操作&#xff1a;2、创建数据库连接如下&#xff1a; 3、配置mysql的url、端口号、账号、密码注意上面的Database URL&#xff1…

ComponentOne FlexGrid for WinForms 中文版快速入门(9)—过滤

C1FlexGrid过滤 表格中的数据过滤通常有两种形式&#xff1a; 基于表头&#xff1a;过滤器的图标出现在有一个过滤器适用于它的每一列。用户可以通过点击过滤器的图标来查看和编辑过滤器。这是Windows 7或Vista或C1FlexGrid控件使用的机制。这种类型的过滤器的主要优点是&…

Pycharm搜索导航之文件名、符号名搜索

1、准备一个工程 向你的工程中添加一个Python文件&#xff0c;并输入一些源码&#xff0c;例如&#xff1a; 2、转到对应文件、类、符号 Pycharm提供的一个很强力的功能就是能够根据名称跳转到任何文件、类、符号所在定义位置。 3、跳转到文件 按下CtrlShiftN快捷键&#xff0c…

分享网页设计当中使用进度条打造精美界面最佳例子

进度条是用户界面的重要组成部分&#xff0c;他向用户显示当前的下载进度&#xff0c;一个小的圆形因素使得界面不是更方便也更容易理解让我们举个例子&#xff0c;想象你去一个网站&#xff0c;你需要下载视频&#xff0c;你选择一个文件&#xff0c;按下"下载"按钮…

基于SqlSugar的开发框架循序渐进介绍(5)-- 在服务层使用接口注入方式实现IOC控制反转

&#x1f680; 优质资源分享 &#x1f680; 学习路线指引&#xff08;点击解锁&#xff09;知识定位人群定位&#x1f9e1; Python实战微信订餐小程序 &#x1f9e1;进阶级本课程是python flask微信小程序的完美结合&#xff0c;从项目搭建到腾讯云部署上线&#xff0c;打造一…

软件项目管理 3.5.敏捷生存期模型

&#x1f680; 优质资源分享 &#x1f680; 学习路线指引&#xff08;点击解锁&#xff09;知识定位人群定位&#x1f9e1; Python实战微信订餐小程序 &#x1f9e1;进阶级本课程是python flask微信小程序的完美结合&#xff0c;从项目搭建到腾讯云部署上线&#xff0c;打造一…

spark内核揭秘-02-spark集群概览

2019独角兽企业重金招聘Python工程师标准>>> Spark集群预览&#xff1a; 官方文档对spark集群的初步描述如下&#xff0c;这是一个典型的主从结构&#xff1a; 官方文档对spark集群中的一些关键点给出详细的指导&#xff1a; 其Worker的定义如下所示&#xff1a; 需…