![](/img/trans.png)
[英]Implicit Conversion from Objective-C Pointer to int * is Disallowed With ARC
[英]Error : Implicit conversion of an Objective-C pointer to 'SEL _Nonnull' is disallowed with ARC in Selector Of NSTimer
我有这样的方法:
-(void)fastTapCartBack:(NSString*)ActionType
我想像这样在NSTimer中将其用作选择器:
self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:[self performSelector:@selector(fastTapCartBack:) withObject:@"FAST"] userInfo:nil repeats:NO]
但是有错误:
ARC不允许将Objective-C指针隐式转换为'SEL _Nonnull'
您正在传递一个方法调用[self performSelector:@selector(fastTapCartBack:) withObject:@"FAST"]
作为选择器,Objective-C不允许这样做
取代这个
self.timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:[self performSelector:@selector(fastTapCartBack:) withObject:@"FAST"] userInfo:nil repeats:NO];
这样
您应该使用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];
您无法在目标/操作模式中传递第二个参数。
但是,对于NSTimer
有一个非常合适的解决方案, userInfo
参数
self.timer = [NSTimer scheduledTimerWithTimeInterval:1
target:self
selector:@selector(fastTapCartBack:)
userInfo:@"FAST"
repeats:NO];
并在选择器方法中获取信息
-(void)fastTapCartBack:(NSTimer *)timer {
NSString *info = (NSString *)timer.userInfo;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.