Create a scrollview and add an imageview to it. The main code for creating an imageView is as follows:
@ Interface ImagePageView: UIView
@ Property (nonatomic, retain) UIImageView * imageViewOne;
@ Property (nonatomic, retain) UIImageView * imageViewTwo;
-(Void) imageViewV :( int) pageNum;
-(Void) imageViewH :( int) pageNum;
@ Implementation ImagePageView
@ Synthesize imageViewOne = _ imageViewOne;
@ Synthesize imageViewTwo = _ imageViewTwo;
-(UIImageView *) imageViewOne
{
If (! _ ImageViewOne ){
_ ImageViewOne = [[UIImageView alloc] init];
[Self addSubview: _ imageViewOne];
}
Return _ imageViewOne;
}
-(UIImageView *) imageViewTwo
{
If (! _ ImageViewTwo ){
_ ImageViewTwo = [[UIImageView alloc] init];
[Self addSubview: _ imageViewTwo];
}
Return _ imageViewTwo;
}
-(Void) imageViewV :( int) pageNum
{
_ ImageViewOne. image = [[[UIImage alloc] initWithContentsOfFile: [[NSBundle mainBundle] pathForResource: [array objectAtIndex: pageNum] ofType: nil] autorelease];
_ ImageViewOne. frame = self. bounds;
}
The result cannot be displayed. Soon I found the problem. The red part should be changed:
Self. imageViewOne. image = [[[UIImage alloc] initWithContentsOfFile: [[NSBundle mainBundle] pathForResource: [array objectAtIndex: pageNum] ofType: nil] autorelease];
Self. imageViewOne. frame = self. bounds;
The reason is that the red code does not call the initialization code (-(UIImageView *) imageViewTwo/-(UIImageView *) imageViewOne). Therefore, imageViewOne is nil and the image cannot be displayed.
Self. imageViewOne calls the get method.