zoukankan      html  css  js  c++  java
  • 面试题

    选择题(每题2分)    

    1、在Xcode中,需要编译混合Objective-C和C++的源码文件,需要将文件格式的后缀改为   答案: C

    A. .c

    B. .cpp

    C. .mm

    D. .m

    2、Objective-C声明一个类所要用到的编译指令是   答案: A

    A. @interface SomeClass

    B. @protocol SomeClass

    C. @implementation SomeClass

    D. @autorelease SomeClass

    3、使用Xcode创建工程时,支持同时创建的版本管理库是  答案: C

    A. Subversion

    B. Mercurial

    C. Git

    D. Concurrent Versions System

    4、使用protocol时,声明一组可选择实现与否的函数,需要在声明的前一行加上:  答案: B

    A. @required

    B. @optional

    C. @interface

    D. @protocol

    5、需要在手动管理内存分配和释放的Xcode项目中引入和编译用ARC风格编写的文件,需要在文件的Compiler Flags上添加参数: 答案: C

    A. -shared

    B. -fno-objc-arc

    C. -fobjc-arc

    D. -dynamic

    6、下面的代码问题在哪?  答案:A

    @implementation xxx

    - (void) setVar:(int)i {

         self.var = i;

    }

    A. 应该将var synthesize

    B. 调用会出现死循环

    C. 正常

    D. 返回值错误

    7、下面那个方法可以比较两个NSString *str1, *str2 的异同  答案: B

    A. if(str1 = str2) xxx ;

    B. if([str1 isEqualToString:str2]) xxx ;

    C. if(str1 && str2) xxx ;

    D. if([str1 length] == [str2 length]) xxx;

    8、在没有navigationController的情况下,要从一个ViewController切换到另一个ViewController应该  答案:D

    A. [self.navigationController pushViewController:nextViewController animated:YES];

    B. [self.view addSubview:nextViewController.view];

    C. [self pushViewController:nextViewController animated:YES];

    D. [self presentModalViewController:nextViewController animated:YES];

    9、什么是key window?  答案: A

    A. App中唯一的那个UIWindow对象

    B. 可以指定一个key的UIWindow

    C. 可接收到键盘输入等事件的UIWindow

    D. 不可以隐藏的那个UIWindow对象

    10、下面那项不是动态语言的特性  答案: B

    A. 在运行时替换一个类

    B. 在运行时动态加载lib文件

    C. 在运行时修改对象中的方法

    D. 在运行时增加对象的方法

    问答题(每题4分)

    1.写一个setter方法用于完成

    #import "RootViewController.h"

    @interface RootViewController ()

    @property (nonatomic, copy) NSString * name;

    @end

    @implementation RootViewController

    // 懒加载

    - (void)setName:(NSString *)name

    {

        if (self.name != name) {

            [self.name release];

            self.name = name;

        }

    }

    2.Difference between shallow copy and deep copy?

    浅拷贝:拷贝的是栈空间,拷贝对象而不拷贝对象空间的内容。浅拷贝是地址相同。

    深拷贝:拷贝的是堆空间,拷贝对象和对象的所有属性,重新复制一份对象。深拷贝地址不同。

    3.What is advantage of categories? What is difference between implementing a category and inheritance?

    category 是类别,为现有的类增加新的方法。

    inheritance是继承,继承父类拥有父类的方法,同时可以在子类中添加新的方法。

    #import "UIImageView+imageWithUrl.h"

    @implementation UIImageView (imageWithUrl)

    /**

     *  brief:    使用类别为UIImageView添加新的方法

     *  param: 网址

     */

    - (void)setimageWithUrl:(NSString *)urlStr

    {

        NSURL * url = [NSURL URLWithString:urlStr];

        

        // 起线程

        dispatch_queue_t queue = dispatch_queue_create("loadImage", DISPATCH_QUEUE_SERIAL); // 创建异步线程队列

        

        dispatch_async(queue, ^{

            UIImage * image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];

            

            // 通知主线程刷新UI

            dispatch_async(dispatch_get_main_queue(), ^{

                self.image = image;

            });

        });

        

    }

    @end

    4.What are KVO and KVC?

    KVO是iOS中的键值监听技术,用来监听某个类的属性。

    KVC是iOS中的键值编码技术,用来为类的属性进行赋值。

    5.Difference between frame and bounds?

    frame是子控件相对于父控件的坐标和大小。

    bounds是控件相对于自己的大小和位置。它的x,y坐标永远是0

    6.When to use NSMutableArray and when to use NSArray? 

    当需要对数组中的元素进行增加删除的时候需要用NSMutableArray,当数组的元素不进行增加删除操作的时候,可以用NSArray.

    7.Give us example of what are delegate methods and what are data source methods of uitableview.

    UITableView是表格控件,本身不能显示数据。需要其他类来提供数据,这个类就是UITableView的代理。

    这个类要遵守tableView的两个协议:UITableViewDataSource, UITableViewDelegate

    // 代理方法

    #pragma mark - UITableViewDataSource, UITableViewDelegate

    /**

     *  返回分区个数

     */

    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

    {

        return 1;

    }

    /**

     *  返回分区的cell的个数

     */

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

    {

        return _dataSource.count;

    }

    /**

     *  返回cell

     */

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

    {

        static NSString * cellId = @"cellID";

        

        UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:cellId];

        

        if (!cell) {

            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];

        }

        

        return cell;

    }

    /**

     *  返回cell的高度

     */

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

    {

        return 44;

    }

    8.Object C中创建线程的方法是什么?如果在主线程中执行代码,方法是什么?如果想延时执行代码、方法又是什么?

    #pragma mark - 创建线程的方法

    - (void)createMyTread

    {

        // 1. 使用NSThread 对象方法

        NSThread * thread = [[NSThread alloc] initWithTarget:self selector:@selector(thread1) object:nil];

        

        // 开启线程

        [thread start];

        

        // 使用NSThread 类方法

        [NSThread detachNewThreadSelector:@selector(thread1) toTarget:self withObject:nil];

        

        // 2. 使用NSOperationQueue

        NSOperationQueue * queue = [[NSOperationQueue alloc] init];

        

        NSInvocationOperation * op =  [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(thread1) object:nil];

        

        [queue addOperation:op];

        

        // 3. GCD

        // 起线程

        dispatch_queue_t q = dispatch_queue_create("loadImage", DISPATCH_QUEUE_SERIAL); // 创建异步线程队列

        

        dispatch_async(q, ^{

            UIImage * image = [UIImage imageWithData:[NSData dataWithContentsOfURL:url]];

            

            // 通知主线程刷新UI

            dispatch_async(dispatch_get_main_queue(), ^{

                self.image = image;

            });

        });

    }

    9.响应者链是什么

    由很多响应者链接在一起组合起来的一个链条称之为响应者链条

    视图的响应事件。

    10.UIViewController在什么时候会加载UIView,换句话说,技术上在哪个时间点会执行loadView。

    在viewWillAppear的时候加载UIView

    11.UITableView是怎样实现Cell的重用的?

    先创建满屏+1个cell,当cell移出屏幕后,系统将cell放入到复用队列中,等待下一次的复用。

    12.如何设计一个可变高度(根据内容自适应高度)的UITableViewCell?

    使用三个类进行计算cell的高度,model, cellFrame类, cell类,根据cell中的子控件的大小来动态调整cell的高度。

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

    14.简述推送流程

    15.block在ARC中和传统的MRC中的行为和用法有没有什么区别,需要注意些什么?

    16.怎样实现一个 singleton的类.给出思路。

    • ios平台怎么做数据的持久化?coredata和sqlite有无必然联系?coredata是一个关系型数
    • 为什么很多内置的类,如TableViewController的delegate的属性是assign不是retain?

    assign防止对象的循环引用。

    19.描述一下属性和成员变量的区别

    属性是属于某个对象的。

    而成员变量是属于某个类的。

    20.描述一下,打包上传Appstore, 发布APP的流程

  • 相关阅读:
    JMeter 压测基础(四)——Java工程测试
    Docker 实战(二)——centos7镜像安装nginx,将安装nginx的centos容器生成新的镜像,并导出
    JMeter压测基础(三)——Mysql数据库
    Jmeter压测基础(二)——Badboy功能、Jmeter参数化、检查点、集合点、动态关联、图形监控
    API 自动化框架
    Python Flask Restful
    【19】Grafana添加Zabbix为数据源
    【18】使用公共邮箱发送邮件
    xls格式转化为txt格式
    【17】自动发现磁盘脚本
  • 原文地址:https://www.cnblogs.com/hanzhuzi/p/4103425.html
Copyright © 2011-2022 走看看