0

I'm trying to create a method inside another method which is then passed into my timer. I'm stuck on the selector section of NSTimer and have no idea how to pass my method into it. I figured I would be able to pass it like I usually do: [self methodHere:parameter] but it's not working.

I get two warnings on the bgTimer = [NStimer.... line in viewDidLoad:

  • ! expected identifier
  • ! expected "]"

.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]];
    }];
}
vikingosegundo
  • 52,040
  • 14
  • 137
  • 178
user3781632
  • 1,618
  • 2
  • 12
  • 15

1 Answers1

2

It should be:

@selector(bgColorCycleWithOutlet:)
jamihash
  • 1,900
  • 1
  • 12
  • 15
  • How would I add the UIButton parameter to that though? I've tried `bgColorCycleWithOutlet:bgColor` but it's asking for another `:` after `bgColor`. `bgColor` is the name of my UIButton declared in my header file. – user3781632 Feb 09 '15 at 06:12
  • Use the userInfo parameter to pass the UIButton. The Timer passes itself as the parameter to the selector. Your bgColorCycleWithOutlet:(UIButton *)outlet should be bgColorCycleWithOutlet:(NSTimer *) timer and then in that method use timer.userInfo to get the button you passed. – jamihash Feb 09 '15 at 06:24