2013-06-28 72 views
0

我在我的AppDelegate中創建一個數組,然後想在另一個視圖控制器中使用它(重複不斷,直到我關閉視圖)。它填充數組,但似乎不動畫。我搜索並編輯了幾天。任何幫助,將不勝感激!無法從AppDelegate動畫我的NSMutableArray

AppDelegate.h

#import <UIKit/UIKit.h> 
#import <Foundation/Foundation.h> 

@interface AppDelegate : UIResponder <UIApplicationDelegate> 

@property (strong, nonatomic) UIWindow *window; 
@property (nonatomic, retain) NSMutableArray *sharedArray1; 
@end 

AppDelegate.m

#import "Scene1.h" 
@synthesize sharedArray1; 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 

int ii; 

for (ii = 1; ii<70;) {  
    [sharedArray1 addObject:[UIImage imageWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"RadarCircle_Active%i.png", ii] ofType:nil]]]]; 
    NSLog(@"Log RadarCircle_Active i: %i",ii); 
    ii = ii + 1; // increment by 1 
} 

return YES; 
} 

像你需要設置sharedArray1的東西你開始添加對象之前Scene1.m

#import "AppDelegate.h" 

-(void)radarActive{ 

float duration1 = 5.5; 

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 
activeRadarImage.animationImages = appDelegate.sharedArray1; 
activeRadarImage.animationDuration = duration1; 
// activeClawImage.animationRepeatCount = count; 
[activeRadarImage startAnimating]; 
} 
+1

'activeRadarImage'非零? – Kevin

+0

這是圖像名稱。它應該是「PNG」類型嗎? – user1467534

+0

當你遇到這樣的問題時,在調試器中遍歷代碼並確保一切都不爲零。 (並使用臨時變量而不是長鏈表達式)。對於'pathForResource:ofType:','ofType'是有原因的,你應該使用'pathForResource:@「foo」ofType:@「png」'而不是'pathForResource:@「foo.png」ofType:nil '。 – Kevin

回答

0

正如@architectpianist說你需要分配第一和嘗試改變

[sharedArray1 addObject:[UIImage imageWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"RadarCircle_Active%i.png", ii] ofType:nil]]]]; 

[sharedArray1 addObject:[UIImage imageWithData:[NSData dataWithContentsOfFile:[[NSBundle mainBundle]pathForResource:[NSString stringWithFormat:@"RadarCircle_Active%i", ii] ofType:@"png"]]]]; 

或U可以這樣做

NSString *imageName = [NSString stringWithFormat:@"RadarCircle_Active%i.png", ii]; 
UIImage *image = [UIImage imageNamed:imageName]; 
NSLog(@"image : %@", image); 
[sharedArray1 addObject:image]; 

查看NSLog。

希望它有幫助。

+0

太棒了!這很好。謝謝! – user1467534

0

在我看來到它。

嘗試添加此啓動循環之前:

self.sharedArray1 = [[NSMutableArray alloc] init];