2010-01-15 72 views
1

我的图像动画有问题。图像动画问题

这里是.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中完成的,并且所有的日志消息都会被触发。但是,我仍然没有看到动画。我究竟做错了什么?

任何想法,将不胜感激。

谢谢,山姆

+0

很难从你发布的代码中发现错误。 我们应该更多地了解你在界面构建器中做了什么(这不容易在这里发布......)。 你确定theFlash被添加到子视图中并且可见吗? – 2010-01-15 08:35:25

回答

1

       你在哪里创建和初始化您的imageArray?
         所以一开始确保您的imageArray不是零和正确初始化:(在你的代码//NSArray *imageArray = [[NSArray alloc] init];你注释行)。 (你也可以检查它的count属性来检查图像是否实际添加到它)

+0

好的,这个工作。然而,我需要调用NSMutableArray alloc init不只是NSArray。这就是问题 – 2010-01-15 08:48:00

+0

是的,你需要使用数组的可变版本,该行只是提示潜在的问题 – Vladimir 2010-01-15 08:51:36

+0

地狱它通过'[imageArray addObject:[UIImage imageNamed:imageName]]''? – 2010-01-15 09:03:44