2010-01-15 73 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