美文网首页iOS技术
(IOS)使用performSelector:withObjec

(IOS)使用performSelector:withObjec

作者: rightmost | 来源:发表于2018-08-10 10:04 被阅读128次

    // 方法一、

    // 把参数放进一个数组/字典,直接把数组/字典当成一个参数传过去,具体方法实现的地方再解析这个数组/字典

    NSArray* array =

    [NSArray arrayWithObjects: @"first", @"second", nil];

    [selfperformSelector:@selector(fooFirstInput:) withObject: array afterDelay:15.0];

    // 方法二、

    // 使用NSInvocation

    SEL aSelector = NSSelectorFromString(@"doSoming:argument2:");

    NSIntegerargument1 =10;

    NSString*argument2 =@"argument2";

    if([selfrespondsToSelector:aSelector]) {

        NSInvocation *inv = [NSInvocation invocationWithMethodSignature:[selfmethodSignatureForSelector:aSelector]];

        [inv setSelector:aSelector];

        [inv setTarget:self];

        [inv setArgument:&(argument1) atIndex:2];

        [inv setArgument:&(argument2) atIndex:3];

        [inv performSelector:@selector(invoke) withObject:nilafterDelay:15.0];

    }

    相关文章

      网友评论

        本文标题:(IOS)使用performSelector:withObjec

        本文链接:https://www.haomeiwen.com/subject/ckqkbftx.html