自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(59)
  • 收藏
  • 关注

原创 iOS7 CookBook精彩瞬间(三)UIActivityViewController的基本使用及自定义Activity

1.基本使用UIActivityViewController主要用于分享内容,创建activityView的方法很简单,调用下面的方法创建:[[UIActivityViewController alloc] initWithActivityItems: applicationActivities:第一个参数为要分享的内容数组,可以为任何类,常见的为NSString和UIImage,

2015-08-31 19:16:57 1421

原创 iOS7 CookBook精彩瞬间(二)NSSet、通过Subscript访问类成员等

1.NSSet的用法   ①NSSet是一种无序集合,基于hash实现,可以在线性时间复杂度内查找某个元素,如果要让元素有序,应当使用NSOrderedSet,要让集合可变,与NSArray类似,使用NSMutableSet和NSMutableOrderedSet即可。   ②从Set中取出元素只能用anyObject随机取,NSSet被系统用于存放用户的触摸点。   ③Set的另

2015-08-31 18:40:01 679

原创 iOS7 CookBook精彩瞬间(一)property、selector细节、__unused

1.我们常常使用nonatomic,很多人只知道它的效率较高,却不知道其含义,其含义是非线程安全的,也就是说多线程修改时不加锁,可能出现多个线程先后修改而成为脏数据的情况。2.unsafe_unretained和assign的作用是一致的,如果对象数据也采用这种方式,这个property就只是指向数据的指针而已,这样说来,似乎assign和weak是一样的,但他们有个很大的区别,在下一条中说明

2015-08-30 21:07:25 1110

原创 1026. Table Tennis (30)

题目如下:A table tennis club has N tables available to the public. The tables are numbered from 1 to N. For any pair of players, if there are some tables open when they arrive, they will be assign

2015-08-29 11:27:36 1272

原创 1080. Graduate Admission (30)

题目如下:It is said that in 2013, there were about 100 graduate schools ready to proceed over 40,000 applications in Zhejiang Province. It would help a lot if you could write a program to automate

2015-08-28 15:31:01 1043

原创 1091. Acute Stroke (30)

题目如下:One important factor to identify acute stroke (急性脑卒中) is the volume of the stroke core. Given the results of image analysis in which the core regions are identified in each MRI slice, you

2015-08-28 14:30:56 1547

原创 1095. Cars on Campus (30)

题目如下:Zhejiang University has 6 campuses and a lot of gates. From each gate we can collect the in/out times and the plate numbers of the cars crossing the gate. Now with all the information ava

2015-08-27 16:30:15 2785

原创 (一二五)手机网络状态的监听

对于一些需要与服务器进行长连接的App,需要对网络状态进行监控,当网络不佳时及时提醒用户,从而提高用户体验。通过苹果自带的框架和Reachability类可以实现网络状态改变的监听。要实现网络监听,按照下面的步骤进行。①导入SystemConfiguration框架。②通过Xcode的帮助文档搜索Reachability,打开样例工程,将其中的Reachability类的代码拷贝到自己

2015-08-25 22:47:54 1017

原创 1030. Travel Plan (30)

原题如下:A traveler's map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to decide the sh

2015-08-25 19:14:09 1470

原创 1090. Highest Price in Supply Chain (25) -计层的BFS改进

题目如下:A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier,

2015-08-24 18:24:04 957

原创 1079. Total Sales of Supply Chain (25) -记录层的BFS改进

题目如下:A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier,

2015-08-23 22:57:03 1142

原创 1076. Forwards on Weibo (30) - 记录层的BFS改进

题目如下:Weibo is known as the Chinese version of Twitter. One user on Weibo may have many followers, and may follow many other users as well. Hence a social network is formed with followers relat

2015-08-23 22:42:46 955

原创 1098. Insertion or Heap Sort (25)

题目如下:According to Wikipedia:Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from

2015-08-22 19:28:28 2130

原创 1077. Kuchiguse (20)

题目如下:The Japanese language is notorious for its sentence ending particles. Personal preference of such particles can be considered as a reflection of the speaker's personality. Such a preferen

2015-08-20 18:10:30 1518

原创 (一二四)tableView的多组数据展示和手动排序

最近在写一个轻量级的网络游戏,遇到了技能优先顺序手动排序的需求,我就想到了iOS自带的tableView编辑功能,对其进行了初步探索,最后做出的效果如下图所示:点击左边可以删除,拖住右边可以手动排序,要实现这个功能,分以下步骤。①用plist存储这些数据,可以看到数据分两个职业,每个职业4个技能,因此建立如下的plist结构:②因为每个职业除了技能还有名称这个属性,因此应该用职

2015-08-19 09:31:40 2358

原创 1096. Consecutive Factors (20)

题目如下:Among all the factors of a positive integer N, there may exist several consecutive numbers. For example, 630 can be factored as 3*5*6*7, where 5, 6, and 7 are the three consecutive number

2015-08-18 19:15:25 3429 2

原创 (一二三)基于GCD的dispatch_once实现单例设计

要实现单例,关键是要保证类的alloc和init只被调用一次,并且被自身强引用防止释放。近日读唐巧先生的《iOS开发进阶》,受益匪浅,通过GCD实现单例就是收获之一,下面把这个方法与大家分享。在GCD中,有一个函数dispatch_once,可以实现代码段的一次性执行,和static修饰的变量赋值的一次性一样,我们结合static和dispatch_once,就可以简单的实现单例。

2015-08-17 21:02:00 1354

原创 1084. Broken Keyboard (20)

题目如下:On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters corresponding to those keys will not appear on screen.Now given a string that you

2015-08-17 19:14:56 855

原创 1081. Rational Sum (20) -最大公约数

题目如下:Given N rational numbers in the form "numerator/denominator", you are supposed to calculate their sum.Input Specification:Each input file contains one test case. Each case starts

2015-08-17 19:10:37 792

原创 1074. Reversing Linked List (25)

题目如下:Given a constant K and a singly linked list L, you are supposed to reverse the links of every K elements on L. For example, given L being 1→2→3→4→5→6, if K = 3, then you must output 3→2→1

2015-08-14 14:16:45 1560

原创 (一二二)核心动画进阶

上节我们介绍了核心动画基础,这一节介绍核心动画的主要应用和局限性。【核心动画的局限性】有一点需要注意,所有的核心动画都是假象,只是修改了View的展示位置,而不能修改真实位置,即使设置了不复位,仿佛是位置移动了,其实layer还在原位,要证明这一点,可以在动画完成后打印layer的位置。为了获得动画结束时机,可以通过代理,UIView已经遵循了相关协议,可以实现动画开始和结束的两个方法

2015-08-13 20:20:18 872

原创 1089. Insert or Merge (25)

题目如下:According to Wikipedia:Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one element from

2015-08-13 12:14:18 1619

原创 (一二一)核心动画基础

核心动画基于QuartzCore框架,只能用于CALayer,可以实现3D效果,它在子线程中执行动画,不会阻塞主线程。要实现核心动画,主要使用CABasicAnimation实现单步动画、使用CAKeyframeAnimation实现帧动画。动画的主要属性有duration、keyPath、value、repeatCount等。动画执行完毕后默认会复位,要取消复位,需要以下两行代码:

2015-08-12 22:39:40 945

原创 (一二〇)CALayer的一些特性

1.每个View都自带一个CALayer,称为rootLayer,layer可以和实现与View一样的显示功能,但是它不继承UIResponse,也就是说它无法处理事件,所以为了处理事件还是要用View,如果只是显示,可以选择layer。下面的代码实现了自定义一个layer添加到控制器的rootLayer上,layer可以正常显示。CALayer *layer = [CALayer lay

2015-08-12 21:20:50 829

原创 (一一九)通过CALayer实现阴影、圆角、边框和3D变换

在每个View上都有一个CALayer作为父图层,View的内容作为子层显示,通过layer的contents属性决定了要显示的内容,通过修改过layer的一些属性可以实现一些华丽的效果。下面以一个普通的蓝色View为例,介绍layer的功能:_blueView.layer.shadowOpacity = 1.0; // 阴影不透明度_blueView.layer.shadowColor

2015-08-12 20:41:50 2289

原创 1086. Tree Traversals Again (25)

题目如下:An inorder binary tree traversal can be implemented in a non-recursive way with a stack. For example, suppose that when a 6-node binary tree (with the keys numbered from 1 to 6) is traver

2015-08-12 14:02:54 3402

原创 (一一八)利用block实现链式编程

有些时候需要不断地调用方法,如果使用传统方案,需要拿到对象多次调用,例如有一个Ball对象,实现了up、down、left、right四个方法,分别控制球的运动方向,如果要实现球向右再向下,需要这么写:[ball right];[ball down];如果能够按照下面这样写,会更加方便。[[ball right] down];要实现这样的功能十分简单,只要每个方法都返回self即可,

2015-08-11 22:26:39 1240

原创 (一一七)基本文件操作 -SDWebImage清除缓存 -文件夹的大小计算

在iOS的App沙盒中,Documents和Library/Preferences都会被备份到iCloud,因此只适合放置一些记录文件,例如plist、数据库文件。缓存一般放置到Library/Caches,tmp文件夹会被系统随机清除,不适宜防止数据。【图片缓存的清除】在使用SDWebImage时,图片被大量的缓存,有时需要获取缓存的大小以及清除缓存。要获取缓存大小,使用SDImag

2015-08-11 22:16:02 1443

原创 1085. Perfect Sequence (25) -二分查找

题目如下:Given a sequence of positive integers and another positive integer p. The sequence is said to be a "perfect sequence" if M Now given a sequence and a parameter p, you are supposed to

2015-08-11 14:27:05 2292

原创 1083. List Grades (25)

题目如下:Given a list of N student records with name, ID and grade. You are supposed to sort the records with respect to the grade in non-increasing order, and output those student records of whic

2015-08-11 14:17:01 706

原创 (一一六)新浪微博客户端的离线缓存实现思路

上一节(一一五)利用NSKeyedArchiver实现任意对象转为二进制介绍了将任意对象转化为二进制数据和还原的方法,可用于实现本节介绍的微博数据离线缓存。通过新浪官方的API可以发现,返回的微博数据如下样式:{ "statuses": [ { "created_at": "Tue May 31 17:46:55 +0800 2011",

2015-08-10 22:49:55 2386

原创 (一一五)利用NSKeyedArchiver实现任意对象转为二进制

【应用背景】在数据库中存储数据时,如果对象过于复杂,又不必要创建复杂的表,可以直接把整个对象转化为二进制存入数据库字段,然后取出后再还原即可。【实现方法】在PHP中,使用序列化和反序列化可以实现这样的功能。在OC中,使用NSKeyedArchiver和NSKedUnarchiver可以实现对象转二进制和二进制转对象,要实现转化,必须遵循NSCoding协议,并且实现encodeWi

2015-08-10 22:32:10 952

原创 (二)表的连接与外键约束

外键约束和表连接【建立表的关系】1.额外建立一张表描述两个表之间的关系,存储两张需要连接的表的主键对应关系。2.利用外键约束外键:一张表的某个字段引用着另一张表的主键,在数据多的表中多一个字段,存储对应的另一张表的主键。外键的创建:CONSTRAINT FOREIGN KEY REFERENCES ();级联:删除了一部分,有对应关系的

2015-08-10 20:35:29 3045

原创 1082. Read Number in Chinese (25)

题目如下:Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way. Output "Fu" first if it is negative. For example, -123456789 is read as "Fu yi Yi

2015-08-10 17:56:30 1270

原创 (一一四)使用FMDB操作SQLite数据库

上节介绍了用系统自带的C语言库操作SQLite的方法,比较繁琐,使用FMDB会大幅度简化,并且是面向对象的,使用十分方便。使用步骤如下:先从github下载FMDB框架,然后把它导入工程。①导入libsqlite3.0.dylib库。②导入主头文件FMDatabase.h。③创建数据库对象,传入路径,打开数据库,如果数据库不存在会被创建。NSString *sqlitePa

2015-08-09 23:51:46 1042

原创 (一一三)使用系统自带框架操作SQLite3数据库

系统自带的框架是基于C语言的,使用比较繁琐。下面是使用步骤:首先导入libsqlite3.0.dylib。①在Document目录下打开数据库,如果没有则创建。NSString *sqlitePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObj

2015-08-09 23:23:21 1147

原创 (一)SQLite与SQL语句基础

数据库一般分为 关系型和对象型,关系型是主流,对象型数据库是直接把对象存入数据库。常用关系型数据库:PC:Oracle MySQL SQL Server DB2嵌入式/移动端:SQLite本文主要介绍SQLite的基本情况与SQL基本语句。1.SQLite实际无类型,但是表层划分数据为以下类型。integer整形real浮点型text文本blob二进制数据

2015-08-09 22:22:06 1325

原创 1078. Hashing (25)

题目如下:The task of this problem is simple: insert a sequence of distinct positive integers into a hash table, and output the positions of the input numbers. The hash function is defined to be "H(k

2015-08-09 19:27:08 617

原创 (一一二)图文混排中特殊文字的点击与事件处理

在上一篇文章(一一一)图文混排基础 -利用正则分割和拼接属性字符串中提到了对attributedText的特殊处理,将其中的话题、URL都用红色进行了表示,如下图所示:本节要实现的功能是这样的attributedText在点击话题、URL时应该有所响应,而在点击其他位置的时候把事件传递给父类处理。要获取到点击的位置很简单,只需要重写touchesBegan方法即可拿到触摸点,比

2015-08-08 23:28:51 7664 2

原创 1075. PAT Judge (25)

题目如下:The ranklist of PAT is generated from the status list, which shows the scores of the submittions. This time you are supposed to generate the ranklist for PAT.Input Specification:E

2015-08-08 19:37:35 962

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除