YYKit---NSObject+YYAdd的学习使用

-(nullable id)performSelectorWithArgs:(SEL)sel, ...;

与- (void)performSelector:(SEL)sel afterDelay:(NSTimeInterval)delay;差不多

立即执行方法sel,使用如下:

1.无arg :[view performSelectorWithArgs:@selector(removeFromSuperView)];

2.arg不是对象:[view performSelectorWithArgs:@selector(setCenter:),CGPointMake(0,0)];

3.arg是对象、且返回值是对象UIImage *image=[UIImage.class performSelectorWithArgs:@selector(imageWithData:sxale:),data,2.0];//这个好像运行不了

4.NSNumber *lengthValue=[@"hello" performSelectorWithArgs:@selector(length)];

NSUinteger length=lengthValue.unsignIntegerValue;

5.NSValue *frameValue=[view performSelectorWithArgs:@selector(frame)];

CGRect frame=frameValue.CGRectValue

ps.该方法在任何线程调用有效。与SEL sel的方法的线程是一致的


-(void)performSelectorWithArgs:(SEL)sel afterDelay:(NSTimeInterVal)delay,...;

过delay秒后执行sel,使用如下:

1.无arg [view performSelectorWithArgs:@selector(removeFromSuperView) afterDelay:2.0];

2.有arg [view performSelector:@selector(setCenter:) afterDelay:2.0,CGPointMake(0,0)];

这个可用于提交资料成功以后,过几秒推回上一个界面。

ps.该方法在子线程不起作用 ,要在主线程调用


-(nullable id)performSelectorWithArgsOnMainThred:@sel waitUntilDone:(BOOL)wait,...;

1.[view performSelectorWithArgsOnMainThread:@selector(removeFromSuperView), waitUntilDone:NO];

//variable arg is not object

2.[view performSelectorWithArgsOnMainThread:@selector(setCenter:), waitUntilDone:NO, CGPointMake(0, 0)];

wait,为no的时候表示异步操作。yes同步操作,要等Sel执行玩才进行下一步。


- (nullable id)performSelectorWithArgs:(SEL)sel onThread:(NSThread *)thread waitUntilDone:(BOOL)wait, ...;

thread 自己传,我测试子线程方法sel不走。待解决




- (void)performSelectorWithArgsInBackground:(SEL)sel, ...;

sel 在子线程运行

你可能感兴趣的:(YYKit---NSObject+YYAdd的学习使用)