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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:06:07+00:00 2026-05-15T16:06:07+00:00

I have a UIImageView object in one of my classes, but I need to

  • 0

I have a UIImageView object in one of my classes, but I need to set that view from within another class.

How is access granted to that method?

Regards

  • 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-15T16:06:08+00:00Added an answer on May 15, 2026 at 4:06 pm

    All interface methods are public by default, so as long as you have access to the object itself, you can call the method.

    However, instance variables are private by default, and not automatically exposed as methods. If you want to write them from outside, you need to declare them as readwrite properties, and either @synthesize or manually implement the corresponding setXXX accessor method. (In the case of an object property like a UIImageView, you should set it as retain as well.)

    See the properties documentation for more details.

    (Note that, while you can pass around a view like any object, if you want it onscreen and participating in event-driven behaviour, there’s usually some other management to do. This will not be supplied by a default @synthesize setter, so writing an explicit accessor is probably the way to go.)

    Longwinded and probably patronising update

    (Feel free to skip to the end for the executive summary!)

    OK, from your comment it seems your problem is more structural than syntactic. Ultimately, you need to think about what objects exist where and who owns which of them. These are design decisions, and there isn’t necessarily one "right" answer; the only thing that is for sure is that if you want object X to be able to do stuff to object Y, then sooner or later it has to be able to get — or be given — a reference to it somehow.

    Now, one way to do this is just to make all the relevant objects into global variables. This is very unfashionable and brings with it a lot of potential problems, but isn’t always wrong. It seems you already know how to do this, since you say that your image index is global.

    Most alternative approaches are ways of wrapping up something that is still tucked into a global somewhere, but making it a bit less exposed. For example, you could make the object a static variable in some file and implement a function or class method in the same file that returns a reference to it. This should be marginally safer, but it amounts to something pretty similar in the end.

    What you will normally do — and probably are even if you haven’t thought about explicitly — is to hang your objects of interest off some main application object. This is what pretty much everyone does pretty much all of the time in a modern GUI app. So there’s still at least one global object somewhere, but the way everything else fits together is much more structured. This is where you have to start thinking about design and ownership and responsibility.

    Your main application object owns everything in it, and everything will ultimately be created as a result of what the app does. The responsibilities will generally be subdivided and shared between a number of auxiliary objects that the top level will create, and these in turn will create others, and so on. In the case of a Cocoa app, some of them might well be created at build time in IB and carbon-frozen into NIB files for subsequent runtime reanimation, but that reanimation will itself be done by one of the app’s levels of control.

    Every object that gets created, of every class you design, is created by something, at some defined point in the program, and has to be owned by something. Something has to be in control — and you should know what it is. For the kind of objects you’re talking about, the things in control will often be controllers (or delegates, or something acting as both). When they create their objects, they are responsible for them. One of those responsibilities is often to set up any links that need to exist between them.

    Of course, I don’t know what the actual structure of your program is. But here are a couple of obvious possibilities:

    If your objects exist in NIB files, then you can link them up in Interface Builder by making sure that there are appropriate IBOutlet fields in their interfaces and then setting those fields in IB. In this case, the runtime chores of linking will be handled during reanimation, and you can just use the IBOutlet ivar in one object to send messages to the other.

    If, on the other hand, the objects are being explicitly created in code, then the code that creates them can pass a reference from one to the other. The receiving object needs to do something with the reference — for example, stash it in an instance variable exposed as a property — but can thereafter use it to invoke methods to do things like set images.

    One likely complication in the latter case is that the relevant objects are being created in different bits of code and different owners have responsibility for them. In which case, you need to adjust your design to accommodate the fact that one needs to know about the other. The crude thing to do would be to bolt on methods up and down the hierarchy until something can see both at once and do the magic joining. Alternatively, you could rethink your design so that it doesn’t require such arbitrary coupling of non-cohesive objects.

    In Short

    If you have object A that needs to do something with object B, either:

    Provide some way of getting a reference to B when you need it, such as a class method +(ClassOfB*)getTheGlobalInstanceB

    Or:

    • Give A an instance variable ClassOfB* theB
    • Declare it as @property (readwrite, retain) ClassOfB* theB in the interface for A
    • In the implementation for A add @synthesize theB
    • At some point in the code where you have created and have access to both A and B, and before A starts actually needing to use B, include a line like A.theB = B

    Recasting this advice in terms of UIImageView etc is left as an exercise for the reader.

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

Sidebar

Related Questions

Example: I have an class that inherits from UIImageView. An object creates an instance
I have an UIImageView object in one of my viewController view that is preloaded
I have an object that return a cached image view (UIImageView), which do the
I have two UIImageView objects inside my view (both 320x480 one above the other).
I have a UIImageView object that when clicked it will play a animation, I
I have a UIImageView object that I rotate with frame property and CFAffineTransformMakeRotate and
I have a UIImageView based class (lets call it classA) that uses a classB
I have a UIImageView object that I instantiate and turn into a property inside
I have two objects: one that is moving by animation, and another that is
i have 3*3 pieces of images from one image(By Croping) but how to manage

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.