How to I pass @selector as a parameter?

后端 未结 5 1036
[愿得一人]
[愿得一人] 2021-01-30 07:00

For the method:

[NSThread detachNewThreadSelector:@selector(method:) toTarget:self withObject:(id)SELECTOR];

How do I pass in a @selector? I tr

5条回答
  •  后悔当初
    2021-01-30 07:12

    If you don't want to specify an object just use nil.

    [NSThread detachNewThreadSelector:@selector(method:) toTarget:self withObject:nil];
    

    If you need to pass an object to the selector it would look something like this.

    Here I'm passing a string to the method "setText".

    NSString *string = @"hello world!";
     [NSThread detachNewThreadSelector:@selector(setText:) toTarget:self withObject:string];
    
    
    -(void)setText:(NSString *)string {
        [UITextField setText:string]; 
    }
    

提交回复
热议问题