UIScrollView的RunTime错误

时间:2013-12-13 05:09:44

标签: ios iphone objective-c uiscrollview uiimageview

我正在尝试将UIImageView对象添加到UIScrollView。

FVImageSequence *imageSquence;
[imageSquence setImage:[UIImage imageNamed: @"car_0.jpg"]];
[scroll addSubview:imageSquence];
scroll.userInteractionEnabled=YES;

imageSequence是FVImageSequence类的一个对象,它继承了UIImageView

@interface FVImageSequence : UIImageView {
NSString *prefix;
int numberOfImages;
int current;
int previous;
NSString *extension;
int increment;
}

但是当我运行代码时它会崩溃。当我使用直接的UIImageView对象时,它工作正常。我该如何解决这个问题?

UIImageView *imageSquence;
[imageSquence setImage:[UIImage imageNamed: @"car_0.jpg"]];
[scroll addSubview:imageSquence];
scroll.userInteractionEnabled=YES;

此代码运行正常。第一个问题出现了什么问题?

4 个答案:

答案 0 :(得分:0)

您必须在使用FVImageSequence对象之前启动(alloc init)

答案 1 :(得分:0)

初始化imageSquence

FVImageSequence *imageSquence = [[FVImageSequence alloc] init];

答案 2 :(得分:0)

使用以下代码:

FVImageSequence *imageSquence = [[FVImageSequence alloc] init];//must initialize FVImageSequence class
[imageSquence setImage:[UIImage imageNamed: @"car_0.jpg"]];
[scroll addSubview:imageSquence];
scroll.userInteractionEnabled=YES;

感谢

答案 3 :(得分:0)

#import <UIKit/UIKit.h>
#import "FVImageSequence.h"
@interface CarViewViewController : UIViewController
{
 IBOutlet FVImageSequence *imageSquence;
 IBOutlet UIScrollView *scroll;
 IBOutlet UIImageView *img;
}
@end



@implementation CarViewViewController

- (void)viewDidLoad
{
   [super viewDidLoad];
   // Do any additional setup after loading the view, typically from a nib.
   [imageSquence setImage:[UIImage imageNamed: @"car_0.jpg"]];
   [scroll addSubview:imageSquence];
   scroll.userInteractionEnabled=YES;
}

这里有效

   [imageSquence setImage:[UIImage imageNamed: @"car_0.jpg"]];
   [scroll addSubview:imageSquence];

并且崩溃了

 [img setImage:[UIImage imageNamed: @"car_0.jpg"]];
   [scroll addSubview:img];