图像动画的问题

时间:2010-01-15 07:53:03

标签: iphone

我的图片动画有问题。

这是.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

这是.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");
}

我做了     indexTimes = 0; 在viewDidLoad方法中。

我的连接在IB中进行,所有日志消息都会触发。但是,我仍然看不到动画。我做错了什么?

任何想法都将不胜感激。

谢谢,Sam

1 个答案:

答案 0 :(得分:1)

您在哪里创建并初始化imageArray? (您在代码中注释了一行://NSArray *imageArray = [[NSArray alloc] init];) 因此,首先请确保您的imageArray不是零并且已正确初始化。 (您还可以检查其计数属性以检查图像是否实际添加到其中)