//SEL是一个类型:方法选择器 @selector(方法名)
[self performSelector:@selector(demo1)];
//2.使用perform调用带有一个参数的方法
[self performSelector:@selector(demo2:) withObject:@"这是一个参数"];
//3.使用perform调用带有两个个参数的方法
[self performSelector:@selector(demo3:withName:) withObject:@"参数1" withObject:@"参数2"];
//4.延迟调用某一个方法 异步
//代码不会停留在这里,这个任务会挂载后台,后面代码继续执行
[self performSelector:@selector(demo1) withObject:NULL afterDelay:2.5];
线程相关:
//6,到主线程上去执行一个方法,参数,是否等待完成
- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait;
//7,和6一样
- (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait modes:(NSArray *)array;
//8,在指定的线程上去执行一个方法
- (void)performSelector:(SEL)aSelector onThread:(NSThread *)thr withObject:(id)arg waitUntilDone:(BOOL)wait modes:(NSArray *)array NS_AVAILABLE(10_5, 2_0);
//9,在指定的线程上执行一个方法
- (void)performSelector:(SEL)aSelector onThread:(NSThread *)thr withObject:(id)arg waitUntilDone:(BOOL)wait NS_AVAILABLE(10_5, 2_0);
// equivalent to the first method with kCFRunLoopCommonModes
//10,开辟新的线程执行一个方法
- (void)performSelectorInBackground:(SEL)aSelector withObject:(id)arg NS_AVAILABLE(10_5, 2_0);
// waitUntilDone:表示是否等待@selector(setImage:)方法执行完成