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

  • Home
  • SEARCH
  • 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 6935735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:08:30+00:00 2026-05-27T12:08:30+00:00

For some reason, I can only display a UIImageView when I alloc/init it each

  • 0

For some reason, I can only display a UIImageView when I alloc/init it each iteration with a different image. What’s strange is I know the image data is being loaded because I am running processing on the image and the processing is working as expected. In short, here are the two methods I was trying:

// interface
@interface ViewController : UIViewController <UIAlertViewDelegate>
{

    UIImageView *imageView;

}

@property (nonatomic, retain) UIImageView *imageView;

@end

// implementation
@implementation ViewController

@synthesize imageView;

//...

- (void) loadAndDisplayImage {

    // Load testing image
    UIImage *testImg;
    testImg = [UIImage imageNamed:@"Test.png"];

    self.imageView = [[UIImageView alloc] initWithImage:testImg];

    //size of imageView rect
    CGRect frame = self.imageView.frame;
    int ivw = frame.size.width;
    int ivh = frame.size.height;

    //...

}

@end

When I use this method self.imageView = [[UIImageView alloc] initWithImage:testImg]; the ivw and ivh have valid values and the image is displayed. However, if I change the implementation to this:

// implementation
@implementation ViewController

@synthesize imageView;

//...

- (void) viewDidLoad {

    self.imageView = [[UIImageView alloc] init];
    [self loadAndDisplayImage];

}

- (void) loadAndDisplayImage {

    // Load testing image
    UIImage *testImg;
    testImg = [UIImage imageNamed:@"Test.png"];

    self.imageView.image = testImg;

    //size of imageView rect
    CGRect frame = self.imageView.frame;
    int ivw = frame.size.width;
    int ivh = frame.size.height;

    //...

}

@end

Where I am setting the image using self.imageView.image = testImg;, the values ivw and ivh are both zero and no image is displayed but the subsequent processing on the image is still accurate. In both cases, I am sending the image to processing using [self doRecognizeImage:self.imageView.image];. I can’t figure out how this is possible. It would make a lot more sense to me if the processing failed when the image could not be shown.

Ideas? Thanks.

  • 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-05-27T12:08:31+00:00Added an answer on May 27, 2026 at 12:08 pm

    The problem is that when you set the image property on an already-init’d UIImageView, the frame size isn’t updated to match the new image size (unlike initWithImage:).

    Whenever you have a problem like this, it’s always worth checking out the docs in case you missed something:

    Setting the image property does not change the size of a UIImageView.
    Call sizeToFit to adjust the size of the view to match the image.

    So, add a call to sizeToFit after you’ve set the image property:

    self.imageView.image = testImg;
    [self.imageView sizeToFit];
    

    As a side note, I’d only use the self. dot notation when you’re writing to a property, not reading it, or calling a method. In other words, you can get away with just writing:

    // we are not setting imageView itself here, only a property on it
    imageView.image = testImg; 
    
    // this is a method call, so "self." not needed
    [imageView sizeToFit];     
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know PHP 5 already supports SQLite but for some reason I can't get
For some reason I can't find a way to get the equivalents of sqlite's
For some reason I can't use runat=server as an attribute for the input tag
For some reason I can't hide WPF Toolkit's DataGridColumn. I am trying to do
I'm fairly new to JQuery and for some reason I can't get the currently
An easy problem, but for some reason I just can't figure this out today.
For some reason beyond me I can't access the mysql server on a machine.
For some reason, I can not seem to change the default position of an
for some reason I'm experiencing the Operational Error with can't rollback message when I
For some reason, we can't update the SVN in some build machines. Installed svn

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.