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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:14:44+00:00 2026-05-16T11:14:44+00:00

In my viewbased application i loaded oneview as mainview and another view as subview

  • 0

In my viewbased application i loaded oneview as mainview and another view as subview of mainview. Its work well the code snippet is ,

In mainviewcontroller,

IBOutlet UIView *subView;
@property(nonatomic,retain) UIView *subView;
@synthesize subView;
[subView release];

//add subview
[self.view addSubview:subView];

//removefromsubview
[subView removeFromSuperview];

This code works fine…..

I dont want to create subview in mainviewcontroller, so i created a new UIView class and its named as subView, now i deleted all declarations of subView from mainviewcontroller and just import subView class in mainviewcontroller. And using this [self.view addSubview:subView];

This things not work great. Can anyone help me … How can i interact a separate UIView class with UIViewcontroller.One more thing is that UIView class have labels and textboxes can i set values from UIViewController to UIView labels and textboxes ……

Is it possible ?

Thanks in advance…….Sorry for my bad english

  • 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-16T11:14:45+00:00Added an answer on May 16, 2026 at 11:14 am

    You have a sub-class called Subview which is declared as a UIView, i.e.

    @interface Subview : UIView {
        UILabel *foo;
    }
    
    @property (nonatomic, retain) UILabel *foo;
    
    @end
    

    Now you want to use this sub-class inside of your main UIView, which you had from the start. There are a few things you need to do.

    1. #import the Subview in your header file, and add an instance of it to your class.

    #import "Subview.h"

    and inside of your @interface‘s {}’s,

    Subview *mySubview;
    

    In the viewDidLoad class for your main view controller, around the bottom, add something like:

    mySubview = [[Subview alloc] init];
    
    [self.view addSubview:mySubview];
    
    [mySubview release];
    

    First line will allocate a new “Subview” for you, second line will add this to your view so you get the stuff it has, and third line will release it. It’s okay to release it here, because “self.view” will now be responsible for it, so it won’t vanish.

    Lastly you need to set the view up in the init method for Subview. In Subview.m, do something like:

    - (id)init
    {
        if (self = [super init]) {
            foo = [[UILabel alloc] init];
            foo.text = @"Hello!";
            [self addSubview:foo];
        }
        return self;
    }
    

    And I think that should take care of it. You also want to release foo in -dealloc for Subview but you probably know how to do that stuff already.

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

Sidebar

Related Questions

I have create a view based application and its loaded correctly what i designed
I created a project using the View-Based Application template. In my mainViewController : -
i created a view based application. All UI control's i created thorough code.But view
I've choosen the view-based application template in Xcode. The myProjectViewController.m has the following code:
From the standard view-based application, I found that the generated code did this: self.window.rootViewController
I've created a new View-based Application in XCode. In the ViewController, the only code
My application is viewbased application in which I have one button. On click of
I have an view-based application where the user can do a lot of customization
I am making a view based application. For one of the xib files, I
I am developing a view based iPad application.It is a simple view based application

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.