Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8276267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:19:22+00:00 2026-06-08T08:19:22+00:00

I am currently dynamically adding a UIImage to my UIScrollView object and everything is

  • 0

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:

NewsViewController.m:

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);

CustomImageView.h:

#import <UIKit/UIKit.h>

@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

CustomImageView.m

#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

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!

IB Screenshot – https://i.stack.imgur.com/gz9UL.png

iOS Simulator No Image with CustomView Screenshot – https://i.stack.imgur.com/zhswq.png

iOS Simulator Image with UIImageView Screenshot – https://i.stack.imgur.com/97vmU.png

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T08:19:24+00:00Added an answer on June 8, 2026 at 8:19 am

    It looks as though CustomImageView is a subclass on UIViewController, not UIImageView or UIView. You can’t add a UIViewController as a subview like that. change it to subclass UIView and it should work.

    To load a UIView from a .nib, you need to declare your IBOutlet properties as you would for a UIViewController. Define the correct custom class in IB and connect everything up, including the base view. Then override the following method inside your custom view class.

    - (id)initWithFrame:(CGRect)frame {
        self = [super initWithFrame:frame];
        if (self) {
        // Initialization code.
        //
        [[NSBundle mainBundle] loadNibNamed:@"<NIB NAME HERE>" owner:self options:nil];
        [self addSubview:self.view];
        }
      return self;
    }
    

    It seems you have cut and pasted methods from a UIViewController subclass into you UIView subclass. Start by deleting all the methods you’ve pasted in between @synthesize and @end . A UIView subclass requires different methods to to load from a .nib, so you need to override the method shown above instead and use the line of code

    [[NSBundle mainBundle] loadNibNamed:@"<NIB NAME HERE>" owner:self options:nil];

    to load the nib.

    Further to your comment about connecting the base view, here is what I mean:

    After creating your custom class and nib file, open the nib and highlight “Files Owner” on the left, then on the top right hand side, select the icon 3rd from the left, looks like an ID card or something. In the “Class” box, add the name of your custom class.

    In your customClass, add an IBOutlet UIView property called baseView, and add a UIView that covers the view in IB at the root level, connect these two. Then add everything else on top of that

    you code would now look something like this:

    CustomImageView.h

    #import <UIKit/UIKit.h>
    
    @interface CustomImageView : UIView
    {
        IBOutlet UIView *baseView
        IBOutlet UIImageView *imageView;
        IBOutlet UILabel *caption;
        IBOutlet UIActivityIndicatorView *activityIndicator;
    }
    @property (nonatomic, retain) IBOutlet UIView *baseView;
    @property (nonatomic, retain) IBOutlet UIImageView *imageView;
    @property (nonatomic, retain) IBOutlet UILabel *caption;
    @property (nonatomic, retain) IBOutlet UIActivityIndicatorView *activityIndicator;
    @end
    

    CustomImageView.m

    #import "CustomImageView.h"  
    @interface CustomImageView ()
    
    @end
    
    @implementation CustomImageView
    
    @synthesize baseView, caption, imageView, activityIndicator;
    
    - (id)initWithFrame:(CGRect)frame {
        self = [super initWithFrame:frame];
        if (self) {
        // Initialization code.
        //
        [[NSBundle mainBundle] loadNibNamed:@"<NIB NAME HERE>" owner:self options:nil];
        [self addSubview:self.baseView];
        }
      return self;
    }
    
    @end
    

    Provided you connect it all up in IB it should work fine, just remember to add the baseView

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

currently, i'm adding elements dynamically to my widget using the following: RemoteViews views =
I am currently dynamically adding content to the page with the help of Jquery.
I'm currently adding custom label controls dynamically at runtime in my WPF app. I've
I have a list in which I am dynamically adding the classname, now when
I am using jQuery Mobile. Currently I am dynamically adding a custom header using
I'm trying to dynamically add Images to a ScrollView. Before adding I check if
I'm working on an iOS project where I want to dynamically add more cell
Currently I have a functioning code for dynamically adding and removing form inputs on
Currently I'm trying to populate a site dynamically. When I step through the code,
I currently have a ajax script that dynamically builds two select boxes enabled with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.