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 3846892
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T16:28:03+00:00 2026-05-19T16:28:03+00:00

I’ve achieved the point of headdesk, trying to dynamically create UIImageView in iOS 4.2.

  • 0

I’ve achieved the point of headdesk, trying to dynamically create UIImageView in iOS 4.2.

This is the code that is causing me trouble:

1) The setup

UIImageView *iview = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 95, 149)];
iview.tag = 200; // see note 1
iview.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;
[self.view addSubview:iview];
[iview release];

I’ve tried with both releasing and not releasing iview.

2) The payoff

NSString *img = ...[see note 2];
NSLog(@"Filename: %@", img);

UIImageView *pIV = (UIImageView *)[self.view viewWithTag:200];
if (pIV == nil) {
    abort();
}

UIImage *pI = [UIImage imageWithContentsOfFile:img];
if (pI == nil) {
    abort();
}
[pIV setImage:pI];

This is expanded to show what I’m looking at, since the terse version wasn’t working for me.

Note 1: Most of the above hardcoded values (200, the frame bounds, etc) are either #defines or computed in the forloop that the iview alloc code is within. Left out for brevity, but let me know if you think it’s relevent.

Note 2: This is just a message that returns the filepath after looking in NSBundle etc. The NSLog output is

2011-01-30 22:09:54.767 ribbit[13529:207] Filename: /Users/rip/Library/Application Support/iPhone Simulator/4.2/Applications/C421AA9F-45BB-41AB-8CB0-1540FABB56D3/ribbit.app/cardfront_a7.png

The .png does exist, and both the sentinels aren’t nil (so neither abort() happens).

I’m convinced that it’s just something basic.

Things I’ve tried:

1) Used IB to generate the UIImageView. When it was wired up correctly, I could see the frame, and the image that was given as the default in IB showed. I still could not, however, alter the image, which is why I moved to dynamically creating them…thought it would be simpler. Eh.

2) Tried using instance variables for the various iviews, but that was unwieldy (there are ten of these UIImageView being generated) and they didn’t work either.

Because all three attempts failed with the same behavior (runs fine, just can’t see the images), I’m assuming that it is just some silly little thing.

I welcome any suggestions you might have.

  • 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-19T16:28:03+00:00Added an answer on May 19, 2026 at 4:28 pm

    The issue appeared to be with the setImage (there wasn’t one) and opaque=YES.

    I was pre-creating the UIImageViews, and then loading them with an image lazily, as needed, which is why the setImage wasn’t in the above code examples. Now I do, and it seems to be working:

    for (int i = 0; i < CARDS_AND_ARROWS; i++) {
        float x = (float)(67 + ((95 + 22) * i));
        UIImageView *iview = [[UIImageView alloc] 
            initWithFrame:CGRectMake(x, 20.0f, 95.0f, 149.0f)];
        [iview setImage:[UIImage imageNamed:@"cardback_a.png"]];
        iview.opaque = YES;
        iview.tag = UPPER_IMG_TAG_0+i;
        iview.autoresizingMask = arm;
        iview.hidden = NO; /* change to YES for distribution */
        [self addSubview:iview];
        [iview release];
    }
    

    Once I’d added those, the cards appeared. It may be that the problem was not /not/ being loaded or displayed, rather it was one of visibility.

    Anyway, fuggedaboutit.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

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.