随笔分类 -  IOS

receiver type *** for instance message is a forward declaration
摘要:转自:http://stackoverflow.com/questions/8815200/receiver-type-for-instance-message-is-a-forward-declarationYou're -init'ing an object without +alloc'ing it. That won't workYou're declaring an object as a non-pointer type, that won't work eitherYou're not calling [super init 阅读全文

posted @ 2014-03-28 16:00 王培 阅读(529) 评论(0) 推荐(0)

copy 的实现原理与深浅拷贝
摘要:转自:http://bbs.9ria.com/thread-210322-1-1.html首先,从copy开始说,简而言之,copy的目的就是生成一个新的实例,然后把其成员都按原实例赋值。对于非指针型的成员,比如BOOL, int, float,这样的赋值可以直接进行。但是对于指针型的数据,比如Objc中用到的对象,就有Deep Copy和Shallow Copy的区别——这个和在C++中的基本上是一样的:是生成新的成员对象,或是指向同一成员对象。了解了这点以后,再看看Copy在 Objetive-C中的实现方式。如果要调用一个对象的copy方法,这个对象必须遵循NSCopying的协议。这个 阅读全文

posted @ 2014-03-26 10:49 王培 阅读(465) 评论(0) 推荐(0)

Avoid strong reference cycles
摘要:转自:http://masteringios.com/blog/2014/03/06/avoid-strong-reference-cycles/With the introduction of ARC, memory management became easier. However, even though you don’t have to worry about when to retain and release, there are still a few rules you need to know in order to avoid memory problems. In th 阅读全文

posted @ 2014-03-24 16:13 王培 阅读(359) 评论(0) 推荐(0)

NSArray的排序方法
摘要:转自:http://blog.csdn.net/lixuwen521/article/details/78488931.sortedArrayUsingSelector(按Key值大小对NSDictionary排序)[plain]view plaincopyNSMutableArray*array=[NSMutableArrayarrayWithObjects:[NSDictionarydictionaryWithObjectsAndKeys:@"Obj0",[NSNumbernumberWithInt:0],nil],[NSDictionarydictionaryWith 阅读全文

posted @ 2014-03-20 16:08 王培 阅读(242) 评论(0) 推荐(0)

关于CGContextSetBlendMode: invalid context 0x0的错误
摘要:转自:http://www.cnblogs.com/leipei2352/p/3496058.html在ios 7的模拟器中,选择一个输入框准备输入时,会触发这个错误,以下是出错详细日志:: CGContextSetBlendMode: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system sta 阅读全文

posted @ 2014-03-19 12:02 王培 阅读(246) 评论(0) 推荐(0)

IOS 获取设备屏幕的尺寸
摘要:// 不包含状态栏CGRect rect1 = [UIScreen mainScreen].applicationFrame;// 包含状态栏(整个屏幕)CGRect rect2 = [[UIScreen mainScreen] bounds];CGSize size = rect.size;CGFloat width = size.width;CGFloat height = size.height; 阅读全文

posted @ 2014-03-18 16:41 王培 阅读(528) 评论(0) 推荐(0)

iOS中控件的Frame属性和Bounds属性的区别
摘要:转自:http://www.cnblogs.com/wisejoker/p/3574889.html在iOS中,每个控件都是继承于UIView的,都会有视图的属性存在,控制这个视图的位置就有Frame和Bounds两个属性frame指的是:该view在父view坐标系统中的位置和大小。(参照点是父亲的坐标系统)其中的坐标是我的左上角坐标相对于我的父视图左上角的坐标。如果我修改坐标,x+50,y+50,那么我就会相对于我的父视图移动,相对于父视图,我向右移动50,向下移动50bounds指的是:该view在本身坐标系统中的位置和大小。(参照点是本身坐标系统)其中的坐标是我的子视图左上角的坐标相对 阅读全文

posted @ 2014-03-17 17:09 王培 阅读(225) 评论(0) 推荐(0)

[Objective-C]关联(objc_setAssociatedObject、objc_getAssociatedObject、objc_removeAssociatedObjects)
摘要:转自:http://blog.csdn.net/onlyou930/article/details/9299169关联 关联是指把两个对象相互关联起来,使得其中的一个对象作为另外一个对象的一部分。 关联特性只有在Mac OS X V10.6以及以后的版本上才是可用的。在类的定义之外为类增加额外的存储空间 使用关联,我们可以不用修改类的定义而为其对象增加存储空间。这在我们无法访问到类的源码的时候或者是考虑到二进制兼容性的时候是非常有用。 关联是基于关键字的,因此,我们可以为任何对象增加任意多的关联,每个都使用不同的关键字即可。关联是可以保证被关联的对象在关联对象的整个生命周期都是可用的(... 阅读全文

posted @ 2014-03-07 15:16 王培 阅读(190) 评论(0) 推荐(0)

关于release后retainCount还是1的问题
摘要:转自:http://www.cocoachina.com/bbs/read.php?tid=175523realse之后再调用还能调用的的问题,我做了这么多年也是经常遇到,也曾经试图寻找原因,就像6楼说的,很多时候都会出现realse过后还能调用的现象。而且对象不是autorealse的。我还遇到过奇葩的是,每次要等上好几秒钟再调用才会出现空指针异常。(代码里绝对没有手动多线程)还有很多时候跟你测试的硬件环境还有关,可以说,ios的内存管理策略虽然一如既往的是一套,但是每个版本都有细微的变化,使用中还是能感觉出来,只是没有官方的说明,无法正确的解释。不过随着一些界面业务该用autoreleas 阅读全文

posted @ 2014-02-26 14:04 王培 阅读(513) 评论(0) 推荐(0)

(oneway void) release中oneway的意思
摘要:oneway is used with the distributed objects API, which allows use of objective-c objects between different threads or applications. It tells the system that it should not block the calling thread until the method returns. Without it, the caller will block, even though the method's return type is 阅读全文

posted @ 2014-02-26 13:10 王培 阅读(498) 评论(0) 推荐(0)

Objective-C的内存管理(一)黄金法则的理解
摘要:转自:http://blog.csdn.net/lonelyroamer/article/details/7666851一、内存管理黄金法则:The basic rule to apple is everything thatincreases the reference counter with alloc,[mutable]copy[WithZone:] or retainis in charge of the corresponding [auto]release.如果一个对象使用了alloc,[mutable] copy,retain,那么你必须使用相应的release或autonre 阅读全文

posted @ 2014-02-26 11:41 王培 阅读(323) 评论(0) 推荐(0)

[Objective C]super dealloc 调用时机
摘要:转自:http://dcm19872007.blog.163.com/blog/static/86519374201311953739818/objective-c 语言中最头疼的事就是内存释放,申明一个变量后记得一定要释放这个变量,在我的iPhone开发笔记中已经有一些这方面的文章,今天在cocoaChina上看见一篇内存释放的帖子,说到我的心坎上了,因为这个问题也是我经常犯的,我们定义的全局变量都是在 - (void)dealloc函数中释放的;里面继承了一个[super dealloc]方法,平时自己释放内存都是写在 [super dealloc]的后面,但是在objective-c 中 阅读全文

posted @ 2014-02-25 11:05 王培 阅读(696) 评论(0) 推荐(0)

XCode5中新建工程后强制使用了ARC,如何去掉?
摘要:打开你的工程,点击目录的工程文件,最顶端蓝色的,然后选择project下你的工程,还是蓝色那项,然后build Settings,然后往下拉,在Apple LLVM 5.0 - Language - Objective C 里有一个选项,Objective-C Automatic Reference Counting 选择NO,就可以了。 阅读全文

posted @ 2014-02-25 11:03 王培 阅读(204) 评论(0) 推荐(0)

alloc retain release函数
摘要: 阅读全文

posted @ 2014-02-23 16:50 王培 阅读(191) 评论(0) 推荐(0)

Objective-C函数重载规则
摘要:是按照函数标签是否重复来判断是否为一个重载函数的。 阅读全文

posted @ 2014-02-22 18:00 王培 阅读(329) 评论(0) 推荐(0)

IOS委托,实现两个UIView相互传值
摘要:转自:http://my.oschina.net/wbei/blog/89325detegate委托在IOS中是一种随处可见的模式,通俗的说,就是我把想做的某件事委托给其他人去做,就好像Java中的接口一样,我只用定义方法的实现,不用过问实现的过程。Demo下载:http://pan.baidu.com/share/link?shareid=131942&uk=101519637创建一个委托并声明一个方法1#import 2@protocol TestDetegate 3- (void)setValue:(NSString *)string;4@end在委托中,并没有实现setValu 阅读全文

posted @ 2014-02-18 21:48 王培 阅读(885) 评论(0) 推荐(0)

UIButton 按钮控件-IOS开发 (实例)
摘要:转自:http://justcoding.iteye.com/blog/1467999UIButton是一个标准的UIControl控件,所以如果你对UIControl不甚了解还是先看一下我的另一篇博文:《UIControl IOS控件编程》一、创建两种方法:1. 常规的 initWithFrameC代码UIButton*btn1=[[UIButtonalloc]initWithFrame:CGRectMake(10,10,80,44)];对代码创建View(UIControl继承自UIView,所以也是view)不甚了解的请参看:《有关View的几个基础知识点》2. UIButton 的一个 阅读全文

posted @ 2014-02-18 20:40 王培 阅读(424) 评论(0) 推荐(0)

在iOS App中增加完整的照片多选功能
摘要:转自:http://blog.csdn.net/jasonblog/article/details/8141850主要参考了ELCImagePickerController,不过由于UI展现上需要定制,所以自己写了个。这是上一篇文章的后续,也是完整版。完成后的效果图如下:完整的源代码放到GitHub上了:https://github.com/siqin/TTImagePicker 阅读全文

posted @ 2014-02-17 10:52 王培 阅读(239) 评论(0) 推荐(0)

iOS代码技巧之判断设备及状态
摘要:转自:http://my.oschina.net/joanfen/blog/149076一、判断设备01//设备名称02return[UIDevice currentDevice].name;0304//设备型号,只可得到是何设备,无法得到是第几代设备05return[UIDevice currentDevice].model;0607//系统版本型号,如iPhone OS08return[UIDevice currentDevice].systemVersion;0910//系统版本名称,如6.1.311return[UIDevice currentDevice].systemName;01 阅读全文

posted @ 2014-02-17 10:46 王培 阅读(382) 评论(0) 推荐(0)

Objective-c的@property 详解
摘要:转自:http://www.cnblogs.com/andyque/archive/2011/08/03/2125728.html 之前很多网友对我翻译的教程中的Property的使用感到有些迷惑不解,搞不清楚什么时候要release,什么时候要self.xxx = nil;同时对于Objecti... 阅读全文

posted @ 2014-02-16 11:07 王培 阅读(2406) 评论(0) 推荐(0)

导航