2

我最近一直在玩 Xcode,却被这个愚蠢的问题困住了。需要帮忙!好的,我在支持文件名 1.jpg、2.jpg...69.jpg 中添加了 69 张图像。它们之所以如此命名,是因为将使用循环通过显示一系列图像来创建动画。这就是我所做的。头文件:

#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

现在的问题是程序没有抛出任何错误,但是当模拟器运行时它只显示空白的灰色屏幕而不是动画。我哪里错了?

4

1 回答 1

1

可能只是您NSMutableArray* images;从未创建过。顺便说一句,它不需要是一个属性,你应该将它创建为一个局部变量viewDidLoad- 否则每次视图加载时你都会不断地向它添加越来越多的图像。

于 2012-07-07T10:57:24.837 回答