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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:36:01+00:00 2026-06-04T18:36:01+00:00

If a subclass is defined as MyView that subclasses UIView , and in the

  • 0

If a subclass is defined as MyView that subclasses UIView, and in the Interface Builder, the view is clicked on, and the Custom Class is already set to MyView.

But in ViewController’s viewDidLoad,

 self.view.foo = ... ;

will create a compile error that says foo is not a property of UIView. I then print out the class of self.view:

NSLog(@"Class of view is %@", NSStringFromClass([self.view class]));

and sure enough, it prints out MyView. Also, not only the first line will not compile, Xcode will not “auto complete” the word “foo” as well. But clearly, the class prints out no as UIView but is MyView, and in my class definition of MyView, I did say:

@property (nonatomic, strong) NSMutableArray *foo;

in the interface .h file, and also in the implementation .m file:

@synthesize foo;

and MyView.h is imported in ViewController.h as well. Why is this so and how to fix this?

  • 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-04T18:36:02+00:00Added an answer on June 4, 2026 at 6:36 pm

    Your UIViewController doesn’t know that its view is meant to be an instance of your MyView subclass.

    You’ll need to cast it

    MyView *myView = (MyView *)self.view;
    myView.foo = @"Whatever";
    

    If you want to simplify this, you can also subclass UIViewController and then just always reference self.myView in your MyViewController subclasses instead of self.view:

    @interface MyViewController : UIViewController
    
    @property (nonatomic, strong) MyView *myView;
    
    @end
    
    
    @implementation MyViewController
    @synthesize myView;
    
    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self) {
                self.myView = (MyView *)self.view;
        }
        return self;
    }
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My class is subclass of UIImageView. I create my custom initializer like this @interface
I have an NSWindow that I defined in interface builder. I want to make
I have a subclass of UIView , that have inherited the - initWithFrame: method.
I have a UITableViewCell subclass with backgroundView set to my own UIView object. This
I have a class which is a subclass of UIView . I am able
some time i see some classes defined as subclass of object class, as class
My View doesn't use an XML layout, I just reference a View subclass defined
If a class defined an annotation, is it somehow possible to force its subclass
I'm getting an error here that says I haven't defined a method, but it
I have an entity class and a subclass based on that entity: @Entity @Inheritance(strategy

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.