tags:

views:

42

answers:

1

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

+1  A: 

    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)

Vladimir
ok, this workd. however, i needed to call NSMutableArray alloc init not just NSArray. therin lies the problem
Sam Jarman
yes, you need to use mutable version of array, that line was just a hint to potential problems
Vladimir
How the hell did it pass '[imageArray addObject:[UIImage imageNamed:imageName]];'?
Kai
if imageArray is nil it will work smoothly - you can send any message to nil without any problems.
Vladimir
yep, you're right. I didn't thougt there would be a Bad_Excess if the alloc is missing.
Kai