我最近一直在玩Xcode并且陷入了这个愚蠢的问题。需要帮忙! 好吧,我添加了69张图片到支持文件名1.jpg,2.jpg ... 69.jpg。它们之所以如此命名,是因为通过显示一系列图像将使用循环来创建动画。这就是我做的。 头文件:
#import <UIKit/UIKit.h>
@interface myBitchViewController : UIViewController{
NSMutableArray *images;
}
@property (retain, nonatomic) NSMutableArray *images;
@end
实施文件:
#import "myBitchViewController.h"
@implementation myBitchViewController
@synthesize images;
- (void)viewDidLoad {
for (int imagenumber = 1; imagenumber <= 69; imagenumber++) {
NSMutableString *myString = [NSMutableString stringWithFormat:@"%i", imagenumber];
[myString stringByAppendingString:@".jpg"];
[images addObject:[UIImage imageNamed:myString]];
}
CGRect frame = CGRectMake(0.0, 0.0, 320.0, 460.0);
UIImageView *imageview = [[UIImageView alloc] initWithFrame:frame];
imageview.animationImages = images;
imageview.contentMode = UIViewContentModeScaleAspectFit;
imageview.animationDuration = 3;
imageview.animationRepeatCount = 0;
[imageview startAnimating];
[self.view addSubview:imageview];
[imageview release];
[super viewDidLoad];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
现在的问题是该程序不会抛出任何错误,但是当模拟器运行时它只显示空白的灰色屏幕而不是动画。我哪里错了?
答案 0 :(得分:1)
可能只是您的NSMutableArray* images;
永远不会被创建。顺便说一句,它不需要是一个属性,你应该在viewDidLoad
中创建它作为局部变量 - 否则你每次都会在视图中添加越来越多的图像负荷。