ios 杂记
1. makeObjectsPerformSelector
- (void)makeObjectsPerformSelector:(SEL)aSelector;
- (void)makeObjectsPerformSelector:(SEL)aSelector withObject:(id)argument;
这是 NSArray和NSSet的两个方法,相信大家很少用,它类似于 for循环,但有效率高于for循环
makeObjectsPerformSelector:类似于NSNotifation机制,并发的执行同一件事,不能像for循环那样区别对待
所以参数 argument 必须是非基本类型 ,如果要是用基本类型 请转换程 NSNumber 或者NSValue
[_leavesLayers makeObjectsPerformSelector:@selector(removeFromSuperlayer)];
2. enumerateObjectsUsingBlock
NSArray *myArray = // 获取数组 [myArray enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([(NSString *)obj isEqualToString:@"Cupertino"]) { NSLog(@”We’re near the mothership!”); *stop = YES; } }];
3. UIGestureRecognizer
http://www.cnblogs.com/pengyingh/articles/2379479.html
4. dateFromComponents
为什么dateFromComponents显示日期与实际日期有差别,貌似少了一天?
是因为没有设置TimeZone,
[self.calendar setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"GMT"]];
5. ios根据设备动态加载
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { //如果是iphone }else { // }