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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:49:21+00:00 2026-05-13T15:49:21+00:00

I had thought I actually had a pretty good handle on the whole view

  • 0

I had thought I actually had a pretty good handle on the whole view controller model, but something just doesn’t seem to making much sense for me. My main issue is with adding a custom UIView subclass as a property of a UIViewController subclass.

Whenever I assign a valid instance of a UIView subclass to that property, nothing happens or the code crashes.

Here’s a quick outline:

  • The main controller inits its own view and that loads fine.
  • I can then add this UIView subclass to the main controller by instantiating it and addSubview:ivar etc. No problems there…

However… if I wanted to have this custom UIView as a property of the ViewController, that does not seem to work. Can anyone shed some light?

Here’s a code summary:

@interface CustomUIView : UIView { }

.

@interface MainViewController : UIViewController {
    CustomUIView *someOtherView;
}

@property (nonatomic, copy)  CustomUIView *someOtherView;

…

- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor greenColor];  // the default controller view

    CustomUIView *tmpView = [[CustomUIView alloc] initWithFrame:CGRectMake(0,0,320,480)];

    [self.view addSubview:tmpView];     // this works

    self.someOtherView = tmpView;       // this does NOT work and
    self.view = self.someOtherView;     // ultimately, this is what i'm after

    [tmpView release];

}

Many thanks to this wonderful community!

  • 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-13T15:49:21+00:00Added an answer on May 13, 2026 at 3:49 pm

    You can’t copy UIViews. Or UIView subclasses. Try retain, instead.

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

Sidebar

Related Questions

I thought I had this figured out but it turns out I'm just deleting
I had thought I was clever. But in light of recent discoveries, I'm not
I thought I had resolved this but I obviously haven't and was hoping someone
I thought I had a good understanding of how quicksort works, until I watched
this seems pretty basic stuff here, but actually i'm finding it a bit harsh
I had thought I could enumerate the types using IMetaDataImport.EnumTypeDefs and for each of
I had thought about decorating various control items with attributes to declare group ownership,
Generally, I had thought it was always better to store images in the filesystem
I had a wild thought today. I've been discovering that my users like my
I closed (or thought I had closed) the BOINC manager, without ending the tasks.

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.