Arrays Can';t从AppDelegate设置NSMutableArray的动画

Arrays Can';t从AppDelegate设置NSMutableArray的动画,arrays,xcode,animation,nsmutablearray,appdelegate,Arrays,Xcode,Animation,Nsmutablearray,Appdelegate,我正在AppDelegate中创建一个数组,然后想在另一个视图控制器中使用它(不断重复,直到关闭视图)。它填充数组,但似乎没有设置动画。我已经搜索和编辑了好几天了。任何帮助都将不胜感激 AppDelegate.h #import <UIKit/UIKit.h> #import <Foundation/Foundation.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @pro

我正在AppDelegate中创建一个数组,然后想在另一个视图控制器中使用它(不断重复,直到关闭视图)。它填充数组,但似乎没有设置动画。我已经搜索和编辑了好几天了。任何帮助都将不胜感激

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

在我看来,在开始向其中添加对象之前,您需要将
sharedArray1
设置为某个值

在开始循环之前,请尝试添加以下内容:

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

正如@architectpianist所说,您需要首先分配并尝试更改

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

或者你可以这样做

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


希望有帮助。

是否
activeRadarImage
非零?这是图像名称。它应该是“png”类型吗?当您遇到类似这样的问题时,请在调试器中逐步检查代码,并确保所有内容都不是nil。(并使用临时变量,而不是长的链式表达式)。对于
pathForResource:ofType:
,类型
的存在是有原因的,您应该使用
pathForResource:@“foo”of type:@“png”
,而不是
pathForResource:@“foo.png”of type:nil
[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"]]]];
NSString *imageName = [NSString stringWithFormat:@"RadarCircle_Active%i.png", ii];
UIImage *image = [UIImage imageNamed:imageName];
NSLog(@"image : %@", image);
[sharedArray1 addObject:image];