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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:21:09+00:00 2026-05-15T07:21:09+00:00

I am building an iPhone Utility app that uses UIImageView to display an animation.

  • 0

I am building an iPhone Utility app that uses UIImageView to display an animation. Within the MainViewController’s viewDidLoad() method, I am creating an instance of a CustomClass, and then setting up the animations:

- (void)viewDidLoad 
{
 [super viewDidLoad]; 
 cc = [CustomClass new];

 NSArray * imageArray = [[NSArray alloc] initWithObjects:
          [UIImage imageNamed:@"image-1-off.jpg"],
          [UIImage imageNamed:@"image-2-off.jpg"],
          [UIImage imageNamed:@"image-3-off.jpg"],
          [UIImage imageNamed:@"image-4-off.jpg"],
          nil];
 offSequence = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
 offSequence.animationImages = imageArray;
 offSequence.animationDuration = .8;
 offSequence.contentMode = UIViewContentModeBottomLeft;
 [self.view addSubview:offSequence];
 [offSequence startAnimating];
}

That works fine. However, I would like to be able to move all the above code that sets up the UIImageView into my CustomClass. The problem is in the second to last line:

[self.view addSubview:offSequence];

I basically need to replace ‘self’ with a reference to the MainControllerView, so I can call addSubview from within my CustomClass. I tried creating an instance var of CustomClass called mvc and a setter method that takes a reference to the MainViewController as an argument as such:

- (void) setMainViewController: (MainViewController *) the_mvc 
{
 mvc = the_mvc;
}

And then I called it within MainViewController like so:

[cc setMainController:MainViewController:self];

But this yields all sorts of errors which I can post here, but it strikes me that I may be overcomplicating this. Is there an easier way to reference the MainViewController that instanatiated my CustomClass?

  • 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-15T07:21:10+00:00Added an answer on May 15, 2026 at 7:21 am

    The cleanest way to do this would be to create a subclass of UIImageView and create a customize initializer that accepts the array. So,

    @interface MyCustomImageView:UIImageView {
    //...
    }
    
    -(id) initWithFrame(CGRect) aRect animationImages:(NSArray *) imageArray;
    @end
    

    Then in your main view controller just initialize the custom image view, populate it and add it to the subviews. This will make everything nicely encapsulated, modular and reusable.

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

Sidebar

Related Questions

I am building an iPhone app that will need to display info primarily in
I'm currently building an iPhone app that will display data from an NSMutableArray called
When building an iPhone app that uses the Core Plot framework, I am seeing
I am building an iphone app that reads a phone number from the address
I'm building an iPhone app, with the following structure: I have the MainViewController which
I am building an iPhone app that has some default data inside it via
I am building an iPhone app that contains medical information for medical professionals. The
I'm building an iPhone app that loads 5 items on a TabBarController. When the
I'm building an Iphone app that needs to convert a UIImage to a CGImageRef.
I'm building an iPhone app that, in part, allows the user to log in

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.