Sam Jarman
Sam Jarman

Reputation: 7377

problem with image animation

I have a problem with my image animation.

here is the .h

@interface Flash_ViewController : UIViewController {

IBOutlet UITextField *textField;
IBOutlet UIButton *generateFlash;
IBOutlet UIImageView *theFlash;

IBOutlet UILabel *testLabel;

NSArray *letterArray;
NSMutableArray *imageArray;
NSTimer *myTimer;
int runLoopTimes;
int indexTimes;
}


-(IBAction) generateFlashNow:(id)sender;


@end

here is the .m

-(IBAction) generateFlashNow:(id)sender{


[textField resignFirstResponder];
/*
NSString *string1 = textField.text;
//NSString *string2 = [string1 stringByReplacingOccurrencesOfString:@"" withString:@","];
NSArray *arrayOfLetters = [string1 componentsSeparatedByString:@","];
*/

NSString *string = textField.text;
NSMutableArray *arrayOfLetters = [[NSMutableArray alloc] init];
for(int i = 0; i < [string length]; i++) {
    NSString *myChar = [NSString stringWithFormat:@"%c", [string characterAtIndex:i]];
    [arrayOfLetters addObject:myChar];
}

NSLog(@"Log Array :%@", arrayOfLetters);

//NSArray *imageArray = [[NSArray alloc] init];

NSLog(@"Log First Letter of array: %@",[arrayOfLetters objectAtIndex:0]);

runLoopTimes = [arrayOfLetters count];

NSLog(@"Letters:%d", runLoopTimes);



while (runLoopTimes > 0) {
    NSLog(@"loopedy Loop");

    NSString *LetterString = [NSString stringWithFormat:@"%@", [arrayOfLetters objectAtIndex:indexTimes]];
    runLoopTimes --;
    NSLog(@"letter String : %@", LetterString);

    NSString *imageName =  [LetterString stringByAppendingString:@".png"];
    NSLog(@" IMAGE NAME: %@", imageName);
    [imageArray addObject:[UIImage imageNamed:imageName]];
    NSLog(@"Added object %d", indexTimes);
    testLabel.text = LetterString;


    indexTimes ++;


}

NSLog(@"done");
runLoopTimes = 0;
indexTimes = 0;

[arrayOfLetters autorelease];
[theFlash setAnimationImages:imageArray];
[theFlash setAnimationRepeatCount:1];
theFlash.animationDuration = 4;
[theFlash startAnimating];
NSLog(@"images flashed");
}

and i make indexTimes = 0; in the viewDidLoad method.

my connections are made in IB, and all log messages fire. But, still i see no animation. What am I doing wrong?

Any ideas would be appreciated.

Thanks, Sam

Upvotes: 1

Views: 216

Answers (1)

Vladimir
Vladimir

Reputation: 170829

    Where do you create and initialize your imageArray? (you have commented line://NSArray *imageArray = [[NSArray alloc] init]; in your code)
     So for a start make sure that your imageArray is not nil and properly initialized. (you can also check its count property to check if images were actually added to it)

Upvotes: 1

Related Questions