I’m working on a script that loops through an array of LED UIImageView’s that are setup in numerical order and are selected by tag. Depending on the step (aka number) it’s on the led image is shown as on or off. The main goal of this method is to take the current step and display the “LED on” image while subtracting it by one and display the “LED off” image for the previous step. So, only one LED should be lit up at a time.
Unfortunately, I can only get the “LED on” image to display correctly. All of the LED’s in the sequence light up, but they never turn off. My first guess is that I’m not subtracting the NSInterger in the right way. However, when I check the log, everything is where it should be. If the current step is 2, previous is 1. No idea why this isn’t working. Thanks!
sequencerLocation and previousLocation are both setup as properties.
- (void)clockLoop:(UInt8)seqClockPulse
{
//cast to an int to use in loop
NSInteger stepCount = sequencerSteps;
//increment sequencer on pulse in
sequencerLocation++;
if(sequencerLocation > stepCount)
{
sequencerLocation = 1;
}
//setup previous step location
previousLocation = (sequencerLocation - 1);
if (previousLocation == 0)
{
previousLocation = stepCount;
}
//change led color in led array
for (UIImageView *led in sequencerLEDArray)
{
if(led.tag == sequencerLocation)
{
UIImageView *previousLed = (UIImageView *)[led viewWithTag:previousLocation];
[previousLed setImage:[UIImage imageNamed:@"images/seq_LED_off.png"]];
NSLog(@"Previous: %d", previousLocation);
UIImageView *currentLed = (UIImageView *)[led viewWithTag:sequencerLocation];
[currentLed setImage:[UIImage imageNamed:@"images/seq_LED_on.png"]];
NSLog(@"Current: %d", sequencerLocation);
}
}
}
viewWithTag:
Discussion
So when you search for
ledby it’s tag from itself, it’s returning itself, but when you search its brother it’s not finding it, that is why I’m suggesting theled.superviewas the place to search for your tag, the parent should be able to find its other child.