我在我的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];
}
'activeRadarImage'非零? – Kevin
這是圖像名稱。它應該是「PNG」類型嗎? – user1467534
當你遇到這樣的問題時,在調試器中遍歷代碼並確保一切都不爲零。 (並使用臨時變量而不是長鏈表達式)。對於'pathForResource:ofType:','ofType'是有原因的,你應該使用'pathForResource:@「foo」ofType:@「png」'而不是'pathForResource:@「foo.png」ofType:nil '。 – Kevin