zoukankan      html  css  js  c++  java
  • iOS 面试题整理(带答案)二

    第一篇面试题整理:

    http://www.cocoachina.com/bbs/read.php?tid-459620.html

    本篇面试题同样:如答案有问题,欢迎指正!

    1.回答person的retainCount值,并解释为什么

    Person * per = [[Person alloc] init];

    self.person = per;

    2

    2.这段代码有什么问题吗:

    @implementation Person

    - (void)setAge:(int)newAge {

    self.age = newAge;

    }

    @end

    正确写法

    {

    if(_age){

    [_age release];

    }

    _age = [newAge retain];

    }

    死循环(扩展:知道如何正确写setter和getter方法)

    3.这段代码有什么问题,如何修改

    for (int i = 0; i < someLargeNumber; i++) { 

    NSString *string = @”Abc”;//常量区

    string = [string lowercaseString];//新的堆区

    string = [string stringByAppendingString:@"xyz"];//新的堆区

    NSLog(@“%@”, string);

    }

    在for循环里添加自动释放池(扩展:常量区的retaincount是怎么个情况)

    4.截取字符串”20 | http://www.baidu.com”中,”|”字符前面和后面的数据,分别输出它们。

    componentsSeparatedByString

    NSString * str = @“20|http://www.baidu.com”;

    for(NSString*s in [str componentsSeparatedByString]){

    NSLog(@“%@“,s);

    }

    5.用obj-c写一个冒泡排序

    for(int i = 0, i < arr.count - 1,i++){

    for (int j = 0,j < arr.count - 1 - i;j++){

    int a = [[arr objectAtIndex:j]intValue];

    int b=[[arr objectAtIndex:j+1]intValue];

    if(a < b){

    [arr replaceObjectAtIndex:j withObject:[NSString stringWithFormat:@“%d”,b]];

    [arr replaceObjectAtIndex:j+1 withObject:[NSString stringWithFormat:@“%d”,a];

    }}}

    6.简述你对UIView、UIWindow和CALayer的理解

    http://blog.csdn.net/kuqideyupian/article/details/7731942

    http://o0o0o0o.iteye.com/blog/1728599

    7.写一个完整的代理,包括声明,实现

    注意手写的准确性

    8.分析json、xml的区别?json、xml解析方式的底层是如何处理的?

    http://www.open-open.com/bbs/view/1324367918671

    http://hi.baidu.com/fevelen/item/a25253ab76f766756cd455b6

    9.ViewController 的 didReceiveMemoryWarning 是在什么时候被调用的?默认的操作是什么?

    http://blog.sina.com.cn/s/blog_68661bd80101nn6p.html

    10.面向对象的三大特征,并作简单的介绍

    封装、继承、多态

    多态:父类指针指向子类对象。两种表现形式:重写(父子类之间)和重载(本类中)

    OC的多态体现是:重写,没有重载这种表现形式

    举例说明:

    @interface Parent : NSObject    //父类

    - (void)simpleCall;

    @end 

    @interface Child_A : Parent   //子类  Child_A

    @end 

    @implementation Child_A

    - (void)simpleCall

    {

        NSLog(@"我是Child_A的simpleCall方法");

    }

    @end

    @interface Child_B : Parent     //子类Child_B

    @end

    - (void)simpleCall

    {

         NSLog(@"我是Child_的simpleCall方法");

    }

    @end

    然后,我们就可以看到多态所展示的特性了:

    Parent * pa=[[Child_A alloc] init];// 父类指针指向子类Child_A对象

    Parent * pb=[[Child_B alloc] init]; //父类指针指向子类Child_B对象

    [pa simpleCall];// 显然是调用Child_A的方法

    [pb simpleCall];// 显然是调用Child_B的方法

    在OC中常看见的多态体现:

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath  

     {  

         static NSString *CellWithIdentifier = @"Cell";  

          UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellWithIdentifier];  

          return cell;  

      } 

    (UITableViewCell *)指向cell子类对象

    11.重写一个NSString类型的,retain方式声明name属性的setter和getter方法

    -(void)settetName:(NSString *)name{

    if(_name){

    [_name release];

    }

     _name = [name retain];

    }

    -(NSString *)getterName{

              return [[_name retain]autorelease];

    12.简述NotificationCenter、KVC、KVO、Delegate?并说明它们之间的区别?

    http://blog.csdn.net/zuoerjin/article/details/7858488

    http://blog.sina.com.cn/s/blog_bf9843bf0101j5px.html

    13.What is lazy loading?

    懒汉模式,只在用到的时候才去初始化。也可以理解成延时加载。我觉得最好也最简单的一个列子就是tableView中图片的加载显示了。一个延时载,避免内存过高,一个异步加载,避免线程堵塞

    14.什么是Protocol?什么是代理?写一个委托的interface?委托的property声明用什么属性?为什么?

    委托的property声明用什么属性是assign(防止循环引用)

    15.分别描述类别(categories)和延展(extensions)是什么?以及两者的区别?继承和类别在实现中有何区别?为什么Category只能为对象添加方法,却不能添加成员变量?

    考虑类目比继承的优点

    类别是把类的实现方法分散到不同的文件中 也可以给类扩展新方法

    延展是给类添加私有方法 只为自己类所见 所使用

    继承可以扩展实例变量 而类别不能

    类别如果可以添加成员变量 就跟继承没什么两样了  而且在上线的项目更新中 用类别笔继承更能维护项目的稳定性

    16.Objective-C有私有方法么?私有变量呢?如多没有的话,有没有什么代替的方法?

    oc没有私有方法 但是有私有变量@property  私有方法可以用延展代替

    17.#import、#include和@class有什么区别

    #import 系统文件、自定义文件引用 不用担心重复引用的问题

    #include 跟#import几乎一样 但是他需要注意不能重复引用

    @class 只是告诉系统有这个类 但是如果在实现类中用到这个类 需要重新用#import导入该类头文件 

    18.谈谈你对MVC的理解?为什么要用MVC?在Cocoa中MVC是怎么实现的?你还熟悉其他的OC设计模式或别的设计模式吗?

    mvc - model view controller   避免了view与model 的强耦合 使代码更灵活 更容易维护 可复用 可扩展   oc其他设计模式有Notification 。target;action.  singleton delegate

    19.如监测系统键盘的弹出

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector( ) name:UIKeyboardWillShowNotification object:nil];

    扩展:ios 弹出键盘挡住UITextView的解决方式

    20.举出5个以上你所熟悉的ios  sdk库有哪些和第三方库有哪些?

    AFWorking/WebKit/SQLite/Core Data/Address Book

    21.如何将产品进行多语言发布?

    http://fengmm521.blog.163.com/blog/static/25091358201291645852889/

    22.如何将敏感字变成**

    search = @"某某某";

        replace = @“***”;

        range = [mstr rangeOfString:search];

        [mstr replaceCharactersInRange:range withString:replace];    

        NSLog(@"%@",mstr);

      

    23.objc中的减号与加号代表什么?

    类方法

    24.单例目的是什么,并写出一个?

    避免重复创建  节省内存空间  

    static Model * model;

    +(id)singleton{

    if(!model){

     @synchronized(self){

    model = [[Model alloc]init];

    }}

    return model;

    }

    25.说说响应链

    http://www.tuicool.com/articles/6jmUje

    从手指触摸屏幕的地方的最上层控件是第一响应者  事件会沿着响应链一直向下传递直到被接受并作出处理

  • 相关阅读:
    Maven核心简析
    块/文件/对象存储对比性概述
    Java SE-基本数据类型对应包装类
    Maven+eclipse快速入门
    IaaS、PaaS、SaaS、CaaS、MaaS五者的区别
    Collections.shuffle()源码分析
    java集合继承关系图
    ArrayList和LinkedList的区别
    ArrayList的实现原理
    session以及分布式服务器session共享
  • 原文地址:https://www.cnblogs.com/lihaibo-Leao/p/5511942.html
Copyright © 2011-2022 走看看