工作之余抽点时间出来写写博文,希望对新接触的朋友有帮助。今天在这里和大家一起学习一下延迟执行
//延迟执行
[self performSelector:@selector(hidenSelf) withObject:nil afterDelay:2];
//消取延迟执行
[[self class] cancelPreviousPerformRequestsWithTarget:self selector:@selector(hidenSelf) object:nil];
拜访官网:https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSObject_Class/Reference/Reference.html
Sending Messages
– performSelector:withObject:afterDelay:
– performSelector:withObject:afterDelay:inModes:
– performSelectorOnMainThread:withObject:waitUntilDone:
– performSelectorOnMainThread:withObject:waitUntilDone:modes:
– performSelector:onThread:withObject:waitUntilDone:
– performSelector:onThread:withObject:waitUntilDone:modes:
– performSelectorInBackground:withObject:
+ cancelPreviousPerformRequestsWithTarget:
+ cancelPreviousPerformRequestsWithTarget:selector:object:
面下给出一个例子:
- (IBAction)Start:(id)sender {
[self performSelector:@selector(doSomething:)];
//[self doSomething:nil];
//[self per
[self performSelectorInBackground:@selector(doSomething:) withObject:nil];
}
-(void)doSomething:(id)inputData
{
if([NSThread isMainThread])
{
NSLog(@"in main thread");
}
else {
NSLog(@"not in main thread");
}
NSLog(@"kkkkk");
}
文章结束给大家分享下程序员的一些笑话语录:
人脑与电脑的相同点和不同点,人脑会记忆数字,电脑也会记忆数字;人脑会记忆程序,电脑也会记忆程序,但是人脑具有感知能力,这种能力电脑无法模仿,人的记忆会影响到人做任何事情,但是电脑只有程序软件。比尔还表示,人脑与电脑之间最重要的一个差别就是潜意识。对于人脑存储记忆的特别之处,比尔表示,人脑并不大,但是人脑重要的功能是联络,人脑会把同样的记忆存储在不同的地方,因此记忆读取的速度就不相同,而这种速度取决于使用的频率和知识的重要性。人脑的记忆存储能力会随着年龄增长而退化,同时记忆的质量也会随着年龄退化。经典语录网