SEL的使用

来源:互联网 发布:oppo网络销售授权书 编辑:程序博客网 时间:2024/06/08 02:31

//SEL的第一种用法:

if 0    SEL  sel;     //1.声明一个SEL变量    sel = @selector(eat);   //2.存储方法名    [per performSelector:sel];  //3.执行sel中存储的方法endif

//SEL的第二种用法:SEL以参数形式出现

[per action:@selector(sleep)];[per action:@selector(play)];//SEL sel(形参) = @selector(sleep)(实参)   //2.SEL存储方法名-(void)action:(SEL)sel   //1. 声明SEL{//判断SEL中的方法是否响应,如果响应,则进入执行if([self respondsToSelector:sel]){    [self performSelector:sel];   //3.执行sel中的方法}else{    NSLog(@"没有响应");}}
1 0