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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:04:46+00:00 2026-05-26T15:04:46+00:00

Well, here’s the situation: I’ve got… a custom class with an UIImageView -property, let’s

  • 0

Well, here’s the situation:
I’ve got…

  • a custom class with an UIImageView-property, let’s call it the Enemy-class
  • a ViewController
  • a NSMutableArray to help create multiple instances of Enemy (called enemies)

and what I want:

  • be able to create an unlimited amount of Enemy-Instances through a method in my ViewController (like [self spawnEnemy];, where self is the ViewController)
  • and, subsequently, display the UIImageView property (let’s call it “enemyImage“) on the view that is controlled by my ViewController

I’ve tried something like this:

-(Enemy *) spawnEnemy
 {
   Enemy *tempEnemy = [Enemy new];
   [enemies addObject:(Enemy*)tempEnemy];
   [self.view addSubview:(UIImageView*)[[enemies objectAtIndex:[enemies count]] enemyImage]];

   //randomLocation is declared in the Enemy-Class and just assigns a random 
   //CGPoint to self.enemyImage.center 
   [[enemies objectAtIndex:[enemies count]] randomLocation];

   return [[enemies objectAtIndex:[enemies count]]createEnemy];
 }

This runs without errors, randomLocation gets called (tried with NSLog), AND if I do something like this in another Method of ViewController:

[[self spawnEnemy] enemyTestMethod];

enemyTestMethod is being executed as well.

But still, no enemieViews are displayed on the screen…
What am I doing wrong?

Thank you so much for your help and time.

==== Edit ====

Here’s the relevant code from Enemy.h/Enemy.m:

@interface Enemy : NSObject
{
    UIImageView *enemyImage;   
}

@property (nonatomic, retain) IBOutlet UIImageView *enemyImage;

-(Enemy*) createEnemy;

//Enemy.m

@implementation Enemy

@synthesize enemyImage, speed;

-(Enemy *) createEnemy
{
    self.enemyImage = [[UIImageView alloc] init];
    [self.enemyImage setImage:[UIImage imageNamed:@"enemy.png"]];
    return self;
}

I also corrected the last line in the spawnEnemy-Method to properly send createEnemy.

  • 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-26T15:04:47+00:00Added an answer on May 26, 2026 at 3:04 pm

    You don’t include the code in Enemy where you alloc/init the UIImageView property. Unless this code explicitly specifies a CGRect with the size and origin that you want, the view will be initialized with CGRectZero, which means even if you’re correctly adding the subview (and it looks like you are) you still won’t see it anywhere.

    Post the Enemy code, and the problem will probably be immediately apparent.

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

Sidebar

Related Questions

Well here is the situation, from the table before I running this code is
Well here is the thing, I have MainForm that call OrderForm.Show(). Now I want
Well here's my problem I have three tables; regions, countries, states. Countries can be
Extreme Android developer newbie here...well, new to Android development, not development in general. I
Well i am here writing some constraints for a db I am working on
Well i need some help here i don't know how to solve this problem.
Well, here's a nice obscure one. I'm trying to compile the latest open transport
Here's one from the No question's too dumb department: Well, as the subject says:
Well, this is my first post here and really enjoying the site. I have
Well, I'm gonna be pretty straightforward here, I just have a piece of code

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.