您的位置:首页 > 职场人生

某易iOS开发面试题

2016-03-15 16:22 555 查看
一、写一个宏 判断当前是否模拟设备

这里考察的对宏的定义

//这里用到的是预定义 条件判断句 形式如下
//if  条件(条件满足就执行 下面 否则跳到elif)
//任意语句
.......N
//elif 条件
//任意语句
//endif
判断当前是否模拟设备 宏定义如下
#if TARGET_IPHONE_SIMULATOR
#define SIMULATOR 1
#elif TARGET_OS_IPHONE
#define SIMULATOR 0
#endif


在代码中药判断是否是模拟器 只需这样判断

if(SIMULATOR)
{NSLog(@"是模拟器")
}
NSLog(@"不是模拟器")


二、有一个单例类型SingletonClass,请实现其sharedInstance方法

单例的实现

+ (id)sharedInstance {
static testClass *sharedInstance = nil;
if (!sharedInstance) {
sharedInstance = [[self alloc] init];
}
return sharedInstance;
}


三、类A已经定义的消息响应函数updatafuc,请将其注册到消息中心,消息中心的名字是updatemsg

考 Notification通知中心

[[NSNotificationCenter defaultCenter] addObserver: self
selector: @selector(updatafuc)
name: @"updatemsg"
object: nil];


已经有一个UIView *aView 实现其连续闪烁效果,一次闪烁(可见->不可见->可见->不可见)的时间为2秒

@interface AppDelegate ()
{
UIView *_containerView;
NSTimer *_timer;
}
@end


- (void) TwoSecondTwinkle
{
//repeats设为YES时每次 invalidate后重新执行,如果为NO,逻辑执行完后计时器无效
-(void)Start{
[NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(TwoSecondTwinkle:)userInfo:nil repeats:YES];
}

- (void)TwoSecondTwinkle:(NSTimer*)timer
{
NSLog(@"开始两秒闪烁")
if(self.isViewLoaded && self.view.window=nil){
[self.window makeKeyAndVisible]
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: