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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:12:24+00:00 2026-06-07T17:12:24+00:00

I have declared a UIView inside a UIViewController class. Can I call this UIView

  • 0

I have declared a UIView inside a UIViewController class. Can I call this UIView in another UIViewController class?

If its possible how can I call it?

  • 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-06-07T17:12:27+00:00Added an answer on June 7, 2026 at 5:12 pm

    Yes, you can use a single instance of a view in a number of views/viewControllers. Typically I do the same with Views that carry advertisements.

    You pass them along as you would do with any other object.
    If you do not create it in Interface Bulder (I suggest creating it programmatically) then you may want to define it within your application delegate rather than a view controller and pass it to the individual view controllers that make use of it.

    Within the view controller just add it as sub view accordingly, as you would do it with any other view too.

    There is one thing though. When you add this view to another super view for the second time or more then it will be removed from its prior super view. That means that you will have to add it as super view again, when its prior super view becomes visible again. A view can only be part of one view hierarchy at a time.


    Sample code, thanks to Gordon:

    /* Untested and simplified */
    AppDelegate.h:
    @property ( strong, nonatomic) ReuseableView reuseableView
    

    ;

    AppDelegate.m

    @synthesize reuseableView; 
    
    /* in didFinishLaunchingWithOptions ...*/ 
    reuseableView = [[alloc] init]; // or init from nib, initwithframe, etc. 
    

    viewController.m

    /* In each view controller that uses the view */
     - (void) viewWillAppear:(BOOL)animated 
    { 
      [self.view addSubview:((AppDelegate*)[UIApplication sharedApplication].delegate).reuseableView]; 
    }
    
     - (void) viewWillDisappear:(BOOL)animated 
    { 
      [((AppDelegate*)[UIApplication sharedApplication].delegate).ReuseableView removeFromSuperview]; 
    

    }


    I am not quite sure whether this removeFromSuperview is really required. The next addSubview will remove it from its existing superview anyway and if addSubview is called on the same super view twice in a row then it does not do any harm. However, it is save using removeFromSuperview at this point.

    Well, summarized that is basically it. You define, create and store your shared view (the reusableView in Gordon’s example) at a common place. The application delegate is a good place for that. In each view’s controller that uses the shared view you fetch it from the delegate and add it as subview to the current view.

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

Sidebar

Related Questions

I have a property declared on a class: .h @interface myClass : UIView {
I have a class that implements UIView and inside - (void)drawRect:(CGRect)rect method I add
I have declared a variable like this @{ int i = 1; } Now,
I have declared std::priority_queue like this. priority_queue < Aircraft, vector<Aircraft>, less<Aircraft> > *q; And
I have tried to cast an implementation of my UIView class to my view
I have a UIViewController class MyClass that initially had no XIB, and was initialized
I have declared a DLL import in my C# program that looks like this:
I have declared branch as a variable in the head. Its a JavaScript function
Suppose that i have UIView viewLoading declared in .h. and i do not directly
Hopefully somebody can help me out here. I have a UIView with 3 text

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.