1倾哺、模擬UIButton的點(diǎn)擊
[self.mycancelbtn sendActionsForControlEvents:UIControlEventTouchUpInside]璃搜;
2铸史、NSArray 快速求總和 最大值 最小值 和 平均值
NSArray *array = [NSArray arrayWithObjects:@"2.0", @"2.3", @"3.0", @"4.0", @"10", nil];
CGFloat sum = [[array valueForKeyPath:@"@sum.floatValue"] floatValue];
CGFloat avg = [[array valueForKeyPath:@"@avg.floatValue"] floatValue];
CGFloat max =[[array valueForKeyPath:@"@max.floatValue"] floatValue];
CGFloat min =[[array valueForKeyPath:@"@min.floatValue"] floatValue];
NSLog(@"%f\n%f\n%f\n%f",sum,avg,max,min);
3、計(jì)算某個(gè)方法體執(zhí)行的時(shí)間
CGFloat BNRTimeBlock (void (^block)(void)) {
mach_timebase_info_data_t info;
if (mach_timebase_info(&info) != KERN_SUCCESS)
return -1.0;
uint64_t start = mach_absolute_time ();
block ();
uint64_t end = mach_absolute_time ();
uint64_t elapsed = end - start;
uint64_t nanos = elapsed * info.numer / info.denom;
return (CGFloat)nanos / NSEC_PER_SEC;
}
4假勿、FLAnimatedImage可以幫你完成GIF的顯示處理
FLAnimatedImage *image = [FLAnimatedImage animatedImageWithGIFData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"url"]]];
FLAnimatedImageView *imageView = [[FLAnimatedImageView alloc] init];
imageView.animatedImage = image;
imageView.frame = CGRectMake(0.0, 0.0, 100.0, 100.0);
[self.view addSubview:imageView];
5借嗽、NSNotification
1、重復(fù)監(jiān)聽(tīng)同一個(gè)通知會(huì)執(zhí)行多次響應(yīng)转培。
2恶导、NSNotification是發(fā)送與處理是同步的,post一個(gè)消息后只有等到觀(guān)察者執(zhí)行相應(yīng)的處理操作后才會(huì)繼續(xù)執(zhí)行后面的代碼浸须。異步使用NSNotificationQueue
3甲锡、addObserver:消息中心會(huì)弱持有observer,而非強(qiáng)持有羽戒。
6缤沦、方法名字符串轉(zhuǎn)化為方法
-(void)printMessage;
1、無(wú)參數(shù). 字符串應(yīng)該寫(xiě)為:@"printMessage"
-(void)printMessage:(NSString *)message;
2易稠、有一個(gè)參數(shù). 字符串應(yīng)該寫(xiě)為:@"printMessage:"
-(void)printMessage:(NSString *)message params:(NSString*)msg2;
3缸废、有兩個(gè)參數(shù).字符串應(yīng)該寫(xiě)為:@"printMessage:params:"
如何將方法名字符串轉(zhuǎn)化為方法:
SEL aSel = NSSelectorFromString(@"方法名字符串");
- (id)performSelector:(SEL)aSelector withObject:(id)object1 withObject:(id)object2;
7、NSHashTable驶社、NSMapTable
NSHashTable 對(duì)應(yīng) NSMutableSet企量。
區(qū)別:前者可以對(duì)加入其中的對(duì)象設(shè)置為弱引用,當(dāng)對(duì)象被釋放的時(shí)候自動(dòng)從NSHashTable中移除亡电。后者對(duì)加入其中的對(duì)象強(qiáng)引用届巩。
NSMapTable 對(duì)應(yīng) NSMutableDictionary
區(qū)別:前者可以對(duì)加入其中的(key,value)設(shè)置弱引用份乒,當(dāng)key恕汇,value被釋放的時(shí)候自動(dòng)從NSMapTable中移除掉。后者對(duì)加入其中的強(qiáng)引用或辖。
8瘾英、數(shù)組與鏈表的區(qū)別:
前者在棧上分配一塊連續(xù)的內(nèi)存空間,并且在編譯階段內(nèi)存空間大小不能改變颂暇,這就導(dǎo)致如存儲(chǔ)的數(shù)據(jù)量小造成內(nèi)存浪費(fèi)缺谴,存儲(chǔ)量大會(huì)導(dǎo)致越界。
鏈表是在堆上動(dòng)態(tài)分配內(nèi)存空間耳鸯,它并不要求連續(xù)的空間湿蛔。
9膀曾、看過(guò)的一些文章
autorelease 自動(dòng)釋放池
淺談ARC
常見(jiàn)的三種循環(huán)引用
iOS 幾種多線(xiàn)程
iOS Category添加屬性
iOS KVO實(shí)現(xiàn)原理