Scrollview cannot display content

Source: Internet
Author: User

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.


 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.