简体   繁体   English

错误:在NSTimer选择器中,ARC无法将Objective-C指针隐式转换为'SEL _Nonnull'

[英]Error : Implicit conversion of an Objective-C pointer to 'SEL _Nonnull' is disallowed with ARC in Selector Of NSTimer

I have a method like this : 我有这样的方法:

-(void)fastTapCartBack:(NSString*)ActionType

And I want to use it as selector in NSTimer like this : 我想像这样在NSTimer中将其用作选择器:

self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:[self performSelector:@selector(fastTapCartBack:) withObject:@"FAST"] userInfo:nil repeats:NO]

But It have Error : 但是有错误:

Implicit conversion of an Objective-C pointer to 'SEL _Nonnull' is disallowed with ARC ARC不允许将Objective-C指针隐式转换为'SEL _Nonnull'

You are passing a method call [self performSelector:@selector(fastTapCartBack:) withObject:@"FAST"] as selector, this is not allowed by Objective-C 您正在传递一个方法调用[self performSelector:@selector(fastTapCartBack:) withObject:@"FAST"]作为选择器,Objective-C不允许这样做

replace this 取代这个

self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:[self performSelector:@selector(fastTapCartBack:) withObject:@"FAST"] userInfo:nil repeats:NO];

By this 这样

You should use NSInvocation way 您应该使用NSInvocation方式

NSMethodSignature * signature = [ViewController instanceMethodSignatureForSelector:@selector(fastTapCartBack:)];
NSInvocation * invocation = [NSInvocation
             invocationWithMethodSignature:signature];
[invocation setTarget:self];
[invocation setSelector:@selector(fastTapCartBack:)];
NSString * argument = @"FAST";
[invocation setArgument:&argument atIndex:2];

self.timer2 = [NSTimer scheduledTimerWithTimeInterval:1 invocation:invocation repeats:NO];

You cannot pass a second parameter in the target / action pattern. 您无法在目标/操作模式中传递第二个参数。

However in case of NSTimer there is a very suitable solution, the userInfo parameter 但是,对于NSTimer有一个非常合适的解决方案, userInfo参数

self.timer = [NSTimer scheduledTimerWithTimeInterval:1 
                                              target:self 
                                            selector:@selector(fastTapCartBack:)
                                            userInfo:@"FAST" 
                                             repeats:NO];

and get the information in the selector method 并在选择器方法中获取信息

-(void)fastTapCartBack:(NSTimer *)timer {
     NSString *info = (NSString *)timer.userInfo;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Objective-C指针到int *的隐式转换不允许使用ARC - Implicit Conversion from Objective-C Pointer to int * is Disallowed With ARC ARC不允许将Objective-C指针强制转换为“ SEL” - Cast of an Objective-C pointer to 'SEL' is disallowed with ARC TPMultiLayoutViewController的ARC转换; ARC不允许将Objective-C指针隐式转换为“ const void *” - ARC conversion of TPMultiLayoutViewController; Implicit conversion of an Objective-C pointer to 'const void *' is disallowed with ARC 使用ARC-sqlite3不允许将Objective-C指针隐式转换为'void *' - implicit conversion of an Objective-C pointer to 'void *' is disallowed with ARC - sqlite3 使用ARC隐式转换指向objective-c指针的间接指针 - implicit conversion of an indirect pointer to an objective-c pointer with ARC 禁止使用arc将ios的间接指针隐式转换为目标c的id指针 - ios implicit conversion of an indirect pointer to an objective c pointer to id is disallowed with arc ARC不允许将非Object-C指针类型void *隐式转换为NSString * __ strong * - Implicit conversion of a non-Objective-C pointer type void* to NSString*__strong* is disallowed with ARC ARC不允许将非目标C指针类型'int *'隐式转换为'Bird *' - Implicit conversion of a non-Objective-C pointer type 'int *' to 'Bird *' is disallowed with ARC 在目标C中进行比较 - ARC不允许将'int'隐式转换为'id' - Comparing in objective C - Implicit conversion of 'int' to 'id' is disallowed with ARC ARC不允许将'NSStringEncoding'(aka'unsigned long')隐式转换为'NSCharacterSet * _Nonnull' - Implicit conversion of 'NSStringEncoding' (aka 'unsigned long') to 'NSCharacterSet * _Nonnull' is disallowed with ARC
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM