面试题4
2015-08-12 09:09
543 查看
58.
线程之间怎么通信?
59. 线程生产者,消费者如何实现?
1 个线程是生产者,一个是消费者如何实现这个模型.
NSMutableArray *dataList;NSLock *dataLock;
- (void) produceAndConsume {
dataList = [[NSMutableArray alloc] init];
dataLock = [[NSLock alloc] init];
[NSThread detachNewThreadSelector:@selector(produce:) toTarget:self withObject:nil];[NSThread detachNewThreadSelector:@selector(consume:) toTarget:self withObject:nil];
}
- (void) produce:(id)arg {
int index = 0;while (1) {
NSNumber *n = [NSNumber numberWithInt:index++];[dataLock lock];
[dataList addObject:n];
[NSThread sleepForTimeInterval:0.5];
}}
- (void) consume:(id)arg {while (1) {
if ([dataList count] > 0) {[dataLock lock];
id obj = [dataList objectAtIndex:0];[dataList removeObject:0];[dataLock unlock];
NSLog(@"消费
obj %@", obj);
}
[NSThread sleepForTimeInterval:1];}
}
60.
不同屏幕怎么适配
iphone, iphone3G, iphone3GS 320x480
iphone4, iphoen4S 640x960 retina
iphone5, iphone5S, 640x1136
写程序需要有 2
套图片 demo.png demo@2x.pngiphone5
适配.
1136/2-44-49
[[UIScreen
mainScreen]
applicationFrame] = (320x460, 320x548)[[UIScreen
mainScreen]
bounds] = (320x480, 320x568)
iPad, iPad2, iPad Mini 1024x768
iPad3, iPad4, 2048x1563
61.
不同版本屏幕旋转怎么适配62.
内存警告应该怎么做
尽量多的释放内存。把一些内容写到文件中,不要保存在内存中。63. iOS5, iOS6, iOS7
区别
64. NSNotification
是同步还是异步的
是同步的.
如果需要异步 必须使用
NSNotificationQueue
实现
A notification center delivers notifications to observers synchronously. In other words, thepostNotification: methods do not return until all observers have received and processed thenotification.
To send notifications asynchronously use NSNotificationQueue.
In a multithreaded application, notifications are always delivered in the thread in which thenotification was posted, which may not be the same thread in which an observer registereditself.
Hope it helps you.
线程之间怎么通信?
59. 线程生产者,消费者如何实现?
1 个线程是生产者,一个是消费者如何实现这个模型.
NSMutableArray *dataList;NSLock *dataLock;
- (void) produceAndConsume {
dataList = [[NSMutableArray alloc] init];
dataLock = [[NSLock alloc] init];
[NSThread detachNewThreadSelector:@selector(produce:) toTarget:self withObject:nil];[NSThread detachNewThreadSelector:@selector(consume:) toTarget:self withObject:nil];
}
- (void) produce:(id)arg {
int index = 0;while (1) {
NSNumber *n = [NSNumber numberWithInt:index++];[dataLock lock];
[dataList addObject:n];
[NSThread sleepForTimeInterval:0.5];
}}
- (void) consume:(id)arg {while (1) {
if ([dataList count] > 0) {[dataLock lock];
id obj = [dataList objectAtIndex:0];[dataList removeObject:0];[dataLock unlock];
NSLog(@"消费
obj %@", obj);
}
[NSThread sleepForTimeInterval:1];}
}
60.
不同屏幕怎么适配
iphone, iphone3G, iphone3GS 320x480
iphone4, iphoen4S 640x960 retina
iphone5, iphone5S, 640x1136
写程序需要有 2
套图片 demo.png demo@2x.pngiphone5
适配.
1136/2-44-49
[[UIScreen
mainScreen]
applicationFrame] = (320x460, 320x548)[[UIScreen
mainScreen]
bounds] = (320x480, 320x568)
iPad, iPad2, iPad Mini 1024x768
iPad3, iPad4, 2048x1563
61.
不同版本屏幕旋转怎么适配62.
内存警告应该怎么做
尽量多的释放内存。把一些内容写到文件中,不要保存在内存中。63. iOS5, iOS6, iOS7
区别
64. NSNotification
是同步还是异步的
是同步的.
如果需要异步 必须使用
NSNotificationQueue
实现
A notification center delivers notifications to observers synchronously. In other words, thepostNotification: methods do not return until all observers have received and processed thenotification.
To send notifications asynchronously use NSNotificationQueue.
In a multithreaded application, notifications are always delivered in the thread in which thenotification was posted, which may not be the same thread in which an observer registereditself.
Hope it helps you.
相关文章推荐
- Java语言面试题
- 程序员必备英语.net版(.net菜鸟的成长之路-零基础到精通)
- 剑指Offer面试题51(Java版):数组中重复的数字
- 黑马程序员——Collection集合、List实现类、泛型
- 30个糟糕的程序员抵不过一款好工具
- 【LeetCode-面试算法经典-Java实现】【114-Flatten Binary Tree to Linked List(二叉树转单链表)】
- 【LeetCode-面试算法经典-Java实现】【113-Path Sum II(路径和)】
- 黑马程序员-Java基础:继承和多态
- 作为码农 ,我们为什么要写作
- 黑马程序员Java笔记——初识Java
- 黑马程序员--Java基础--集合(一)
- 黑马程序员——ios学习笔记 OC Foundation—NSArray&NSDictionary
- 黑马程序员——ios学习笔记 OC Foundation—NSString
- 黑马程序员——ios学习笔记 OC 分类
- 黑马程序员——ios学习笔记 OC 协议&Block
- 送上一篇应付Java 面试的秘籍(Java 初级)
- 黑马程序员——包、权限修饰符、内部类
- 黑马程序员
- 为什么程序员的业余项目大多都死了?
- 红杏: 为学者、程序员、外贸工作者打造的上网加速器,专治各种网站打不开和打开慢,而且,更棒的是,红杏