Note that there are some explanatory texts on larger screens.

plurals
  1. POUIView is not showing up in UIScrollView
    primarykey
    data
    text
    <p>I am currently dynamically adding a UIImage to my UIScrollView object and everything is working as intended. I need to add extra functionality now (a UIActivityIndicator in the center of the image when it is loading from the internet, and a label underneath) so I thought why not create a custom View which has all of these laid out as I need them to be, and then just load it into the scrollView. I have encountered a problem though, when I add it to the scrollView, nothing shows up. Here is what I have:</p> <p>NewsViewController.m:</p> <pre><code>imageScrollView.contentSize = CGSizeMake(320*numberOfPages, 303); pageControl.numberOfPages = numberOfPages; dispatch_queue_t imageDownload = dispatch_queue_create("imageDownload", NULL); __block NSData *temp; CustomImageView *customImageView = [[CustomImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 303)]; [imageScrollView addSubview:customImageView]; [[customImageView activityIndicator] startAnimating]; dispatch_async(imageDownload, ^{ temp = [[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://www.wlfarm.org/wp-content/uploads/2012/05/farm.jpg"]]retain]; dispatch_async(dispatch_get_main_queue(), ^{ customImageView.imageView.image = [[UIImage alloc] initWithData:temp]; [[customImageView activityIndicator] stopAnimating]; [customImageView setNeedsDisplay]; customImageView.caption.text = @"HAHAHAHAHHAHA"; [imageScrollView setNeedsDisplay]; [temp release]; }); }); dispatch_release(imageDownload); </code></pre> <p>CustomImageView.h:</p> <pre><code>#import &lt;UIKit/UIKit.h&gt; @interface CustomImageView : UIView { IBOutlet UIImageView *imageView; IBOutlet UILabel *caption; IBOutlet UIActivityIndicatorView *activityIndicator; } @property (nonatomic, retain) IBOutlet UIImageView *imageView; @property (nonatomic, retain) IBOutlet UILabel *caption; @property (nonatomic, retain) IBOutlet UIActivityIndicatorView *activityIndicator; @end </code></pre> <p>CustomImageView.m</p> <pre><code>#import "CustomImageView.h" @interface CustomImageView () @end @implementation CustomImageView @synthesize caption, imageView, activityIndicator; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view from its nib. } - (void)viewDidUnload { [super viewDidUnload]; // Release any retained subviews of the main view. // e.g. self.myOutlet = nil; } - (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation { return (interfaceOrientation == UIInterfaceOrientationPortrait); } @end </code></pre> <p>I am including a screenshot of my XIB file, and the program running on the simulator. The first picture shows nothing in the scrollView(the attempt made by using my custom class), and the second page of the scroll view is the attempt made by adding a UIImageView to the UIScrollView(which worked). Can anyone point out what I am doing wrong? Am I not allowed to load a custom view into a UIScrollView? Thanks for your help!</p> <p>IB Screenshot - <a href="http://i.stack.imgur.com/gz9UL.png" rel="nofollow">http://i.stack.imgur.com/gz9UL.png</a></p> <p>iOS Simulator No Image with CustomView Screenshot - <a href="http://i.stack.imgur.com/zhswq.png" rel="nofollow">http://i.stack.imgur.com/zhswq.png</a></p> <p>iOS Simulator Image with UIImageView Screenshot - <a href="http://i.stack.imgur.com/97vmU.png" rel="nofollow">http://i.stack.imgur.com/97vmU.png</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload