iOS面试题iOS DeveloperiOS总结

IOS总结(三)

2016-09-13  本文已影响91人  梦醒繁华

1.将一个函数在主线程执行的4种方法

dispatch_async(dispatch_get_main_queue(),^{
需要执行的方法
});
NSOperationQueue *mainQueue = [NSOperationQueue mainQueue];//主队列
NSBlockOperation *operation = [NSBlockOperation blockOperationWithBlack:^{
需要执行的方法
}];
[mainQueue addOperation:operation];
 [self performSelector:@selector(method) onThread:[NSThread mainThread] withObject:nil waitUntilDone:YES modes:nil];
 [self perfromSelectorOnMainThread:@selector(method) withObject:nil waitUntilDone:YES];
[[NSThread mainThread] performSelector:@selector(method) withObject:nil];
[NSRunLoop mainRunLoop]performSelector:@selector(method) withObject:nil];

2.如何让计时器调用一个类方法

[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerMethod) userInfo:nil repeats:YES];
-(void)timerMethod
{
   调用类方法
   [[self class] staticMethod];

}

-(void)invalid

{

   [timer invalid];

   timer =nil;

}

3.KVO,NSNotification,delegate及block区别

4.如何重写类方法

5.NSTimer创建后,会在哪个线程运行。

上一篇下一篇

猜你喜欢

热点阅读