iOS开发面试题大全-3
2016-03-18 13:23
573 查看
描述应用程序的启动顺序。
1、程序入口main函数创建UIApplication实例和UIApplication代理实例
2、在UIApplication代理实例中重写启动方法,设置第一ViewController
3、在第一ViewController中添加控件,实现对应的程序界面。
为什么很多内置类如UITableViewControl的delegate属性都是assign而不是retain?请举例说明。
防止循环引用,
Student * str=[];
Teacher *teacher=[[Teacher alloc] init];
Student * student=[[Student alloc] init];
teacher.delegate=student;
student.delegate= teacher;
在teacher中dealloc会release当前的Delegate,就会触发student对象release,继而也会导致student执行dealloc,在student中也会release自己的delegate,产生循环了。
使用UITableView时候必须要实现的几种方法?
2个。
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section; 这个方法返回每个分区的行数
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath)indexPath;这个方法返回我们调用的每一个单元格
写一个便利构造器。
+ (id)studentWithName:(NSString *)newName andAge:(int)newAge
{
Student *stu = [[Student alloc] initWithName:newName andAge:newAge];
return [stu autorelease];
}
UIImage初始化一张图片有几种方法?简述各自的优缺点。
1、从资源读取
UIImage *image = [UIImage imageNamed:@”1.png”];
2、从网络读取
NSURL*url=[NSURL URLWithString:@"http://www.sinaimg.cn/qc/photo_auto/chezhan/2012/50/00/15/80046_950.jpg"];
3.从手机本地读取
//读取本地图片非resource
NSString *aPath3=[NSString stringWithFormat:@"%@/Documents/%@.jpg",NSHomeDirectory(),@"test"];
UIImage *imgFromUrl3=[[UIImage alloc]initWithContentsOfFile:aPath3]; 4.从现有的context中获得图像
//添加 ImageIO.framework and #import <ImageIO/ImageIO.h>
CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef)url, NULL);
CGImageRef img= CGImageSourceCreateImageAtIndex(source,0,NULL);
CGContextRef ctx=UIGraphicsGetCurrentContext();
CGContextSaveGState(ctx);
//transformCTM的2种方式
//CGContextConcatCTM(ctx, CGAffineTransformMakeScale(.2, -0.2));
//CGContextScaleCTM(ctx,1,-1);
//注意坐标要反下,用ctx来作为图片源
CGImageRef capture=CGBitmapContextCreateImage(ctx);
CGContextDrawImage(ctx, CGRectMake(160, 0, 160, 230), [image CGImage]);
CGContextDrawImage(ctx, CGRectMake(160, 230, 160, 230), img);
CGImageRef capture2=CGBitmapContextCreateImage(ctx);
5、用Quartz的CGImageSourceRef来读取图片
CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef)url, NULL);
CGImageRef img= CGImageSourceCreateImageAtIndex(source,0,NULL);
参考(http://blog.csdn.net/jerryvon/article/details/7526147#)
回答person的retainCount值,并解释为什么
Person * per = [[Person alloc] init];
self.person = per;
person属性如果为assign的话retainCount为1,如果为retain的话retainCount为2
这段代码有什么问题吗:
@implementation Person
- (void)setAge:(int)newAge {
self.age = newAge;
}
@end
死循环
这段代码有什么问题,如何修改
for (int i = 0; i < someLargeNumber; i++) {
NSString *string = @”Abc”;
string = [string lowercaseString];
string = [string stringByAppendingString:@"xyz"];
NSLog(@“%@”, string);
}
如果数字很大的话会造成内存一直增加(因为一直通过便利构造器方法创建autorelease对象),直到循环结束才减少,在循环内加一个自动释放池,更改后代码如下:
for (int i = 0; i < someLargeNumber; i++) {
NSString *string = @”Abc”;
@autoreleasepool {
string = [string lowercaseString];
string = [string stringByAppendingString:@"xyz"];
NSLog(@“%@”, string);
}
}
截取字符串”20 |
http://www.baidu.com”中,”|”字符前面和后面的数据,分别输出它们。
NSString *string = @” 20 | http://www.baidu.com”;
[string componentsSeparatedByString:@”|”];
用obj-c写一个冒泡排序
[align=left] NSMutableArray *array = [NSMutableArray arrayWithArray:@[@"3",@"1",@"10",@"5",@"2",@"7",@"12",@"4",@"8"]];[/align]
[align=left] NSString *tmp;[/align]
[align=left] for (int i = 0; i < array.count; i ++) {[/align]
[align=left] for (int j = 0; j < array.count - 1 - i; j++) {[/align]
[align=left] if ([[array objectAtIndex:j] integerValue] > [[array objectAtIndex:j + 1] integerValue]) {[/align]
[align=left] tmp = [array objectAtIndex:j];[/align]
[align=left] [array replaceObjectAtIndex:j withObject:[array objectAtIndex:j + 1]];[/align]
[align=left] [array replaceObjectAtIndex:j + 1 withObject:tmp];[/align]
[align=left] }[/align]
[align=left] }[/align]
[align=left] }[/align]
1、程序入口main函数创建UIApplication实例和UIApplication代理实例
2、在UIApplication代理实例中重写启动方法,设置第一ViewController
3、在第一ViewController中添加控件,实现对应的程序界面。
为什么很多内置类如UITableViewControl的delegate属性都是assign而不是retain?请举例说明。
防止循环引用,
Student * str=[];
Teacher *teacher=[[Teacher alloc] init];
Student * student=[[Student alloc] init];
teacher.delegate=student;
student.delegate= teacher;
在teacher中dealloc会release当前的Delegate,就会触发student对象release,继而也会导致student执行dealloc,在student中也会release自己的delegate,产生循环了。
使用UITableView时候必须要实现的几种方法?
2个。
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section; 这个方法返回每个分区的行数
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath)indexPath;这个方法返回我们调用的每一个单元格
写一个便利构造器。
+ (id)studentWithName:(NSString *)newName andAge:(int)newAge
{
Student *stu = [[Student alloc] initWithName:newName andAge:newAge];
return [stu autorelease];
}
UIImage初始化一张图片有几种方法?简述各自的优缺点。
1、从资源读取
UIImage *image = [UIImage imageNamed:@”1.png”];
2、从网络读取
NSURL*url=[NSURL URLWithString:@"http://www.sinaimg.cn/qc/photo_auto/chezhan/2012/50/00/15/80046_950.jpg"];
3.从手机本地读取
//读取本地图片非resource
NSString *aPath3=[NSString stringWithFormat:@"%@/Documents/%@.jpg",NSHomeDirectory(),@"test"];
UIImage *imgFromUrl3=[[UIImage alloc]initWithContentsOfFile:aPath3]; 4.从现有的context中获得图像
//添加 ImageIO.framework and #import <ImageIO/ImageIO.h>
CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef)url, NULL);
CGImageRef img= CGImageSourceCreateImageAtIndex(source,0,NULL);
CGContextRef ctx=UIGraphicsGetCurrentContext();
CGContextSaveGState(ctx);
//transformCTM的2种方式
//CGContextConcatCTM(ctx, CGAffineTransformMakeScale(.2, -0.2));
//CGContextScaleCTM(ctx,1,-1);
//注意坐标要反下,用ctx来作为图片源
CGImageRef capture=CGBitmapContextCreateImage(ctx);
CGContextDrawImage(ctx, CGRectMake(160, 0, 160, 230), [image CGImage]);
CGContextDrawImage(ctx, CGRectMake(160, 230, 160, 230), img);
CGImageRef capture2=CGBitmapContextCreateImage(ctx);
5、用Quartz的CGImageSourceRef来读取图片
CGImageSourceRef source = CGImageSourceCreateWithURL((CFURLRef)url, NULL);
CGImageRef img= CGImageSourceCreateImageAtIndex(source,0,NULL);
参考(http://blog.csdn.net/jerryvon/article/details/7526147#)
回答person的retainCount值,并解释为什么
Person * per = [[Person alloc] init];
self.person = per;
person属性如果为assign的话retainCount为1,如果为retain的话retainCount为2
这段代码有什么问题吗:
@implementation Person
- (void)setAge:(int)newAge {
self.age = newAge;
}
@end
死循环
这段代码有什么问题,如何修改
for (int i = 0; i < someLargeNumber; i++) {
NSString *string = @”Abc”;
string = [string lowercaseString];
string = [string stringByAppendingString:@"xyz"];
NSLog(@“%@”, string);
}
如果数字很大的话会造成内存一直增加(因为一直通过便利构造器方法创建autorelease对象),直到循环结束才减少,在循环内加一个自动释放池,更改后代码如下:
for (int i = 0; i < someLargeNumber; i++) {
NSString *string = @”Abc”;
@autoreleasepool {
string = [string lowercaseString];
string = [string stringByAppendingString:@"xyz"];
NSLog(@“%@”, string);
}
}
截取字符串”20 |
http://www.baidu.com”中,”|”字符前面和后面的数据,分别输出它们。
NSString *string = @” 20 | http://www.baidu.com”;
[string componentsSeparatedByString:@”|”];
用obj-c写一个冒泡排序
[align=left] NSMutableArray *array = [NSMutableArray arrayWithArray:@[@"3",@"1",@"10",@"5",@"2",@"7",@"12",@"4",@"8"]];[/align]
[align=left] NSString *tmp;[/align]
[align=left] for (int i = 0; i < array.count; i ++) {[/align]
[align=left] for (int j = 0; j < array.count - 1 - i; j++) {[/align]
[align=left] if ([[array objectAtIndex:j] integerValue] > [[array objectAtIndex:j + 1] integerValue]) {[/align]
[align=left] tmp = [array objectAtIndex:j];[/align]
[align=left] [array replaceObjectAtIndex:j withObject:[array objectAtIndex:j + 1]];[/align]
[align=left] [array replaceObjectAtIndex:j + 1 withObject:tmp];[/align]
[align=left] }[/align]
[align=left] }[/align]
[align=left] }[/align]
相关文章推荐
- iOS开发面试题大全-1
- 经验总结、自己出的面试题及参考
- 面试阿里数据研发岗,无缘三面,谈谈面经
- 电话面试
- 传统的程序员将会被淘汰
- 向大牛学习!11名顶尖设计师的设计启迪+职业忠告
- 剑指offer面试题之求二叉树的深度
- 2016年JS面试题目汇总
- Remove Duplicates from Sorted Array
- 反转字符串的多种方式-经典面试题系列
- Java线程面试题
- 面试博客收集
- java常考面试题
- PHP程序员学习路线
- 操作系统常见面试题总结
- 程序员,凭什么让你拿二十万
- 程序员想打基础看哪几本书合适?
- 面试这样谈薪才有戏!
- 2016/3/17面试的总结
- 2016年Web前端面试题目汇总