尝试将带有参数的方法作为选择器传递时出错
Errors when trying to pass a method with parameters as a selector
我正在尝试在另一个方法中创建一个方法,然后将其传递到我的计时器中。我停留在 NSTimer 的 selector
部分,不知道如何将我的方法传递给它。我想我可以像往常一样通过它:[self methodHere:parameter]
但它不起作用。
我在 viewDidLoad 的 bgTimer = [NStimer....
行收到两个警告:
- !预期标识符
- !预期“]”
.m
- (void)viewDidLoad {
[super viewDidLoad]
timer = [NSTimer scheduledTimerWithTimeInterval:animationDuration target:self selector:@selector([self bgColorCycleWithOutlet:bgColor]) userInfo:nil repeats:YES];
}
- (void)bgColorCycleWithOutlet:(UIButton *)outlet {
if (time == 0) {
[self bgColorSwatchAnimationRed:232
green:152
blue:58
duration:5
outlet:outlet];
}
}
- (void)bgColorSwatchAnimationRed:(float)r green:(float)g blue:(float)b duration:(int)d outlet:(UIButton *)o {
[o setBackgroundColor:[UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:0.5]];
[UIView animateWithDuration:d animations:^{
[o setBackgroundColor:[UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]];
}];
}
应该是:
@selector(bgColorCycleWithOutlet:)
我正在尝试在另一个方法中创建一个方法,然后将其传递到我的计时器中。我停留在 NSTimer 的 selector
部分,不知道如何将我的方法传递给它。我想我可以像往常一样通过它:[self methodHere:parameter]
但它不起作用。
我在 viewDidLoad 的 bgTimer = [NStimer....
行收到两个警告:
- !预期标识符
- !预期“]”
.m
- (void)viewDidLoad {
[super viewDidLoad]
timer = [NSTimer scheduledTimerWithTimeInterval:animationDuration target:self selector:@selector([self bgColorCycleWithOutlet:bgColor]) userInfo:nil repeats:YES];
}
- (void)bgColorCycleWithOutlet:(UIButton *)outlet {
if (time == 0) {
[self bgColorSwatchAnimationRed:232
green:152
blue:58
duration:5
outlet:outlet];
}
}
- (void)bgColorSwatchAnimationRed:(float)r green:(float)g blue:(float)b duration:(int)d outlet:(UIButton *)o {
[o setBackgroundColor:[UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:0.5]];
[UIView animateWithDuration:d animations:^{
[o setBackgroundColor:[UIColor colorWithRed:r/255.0 green:g/255.0 blue:b/255.0 alpha:1]];
}];
}
应该是:
@selector(bgColorCycleWithOutlet:)