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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:21:31+00:00 2026-05-26T04:21:31+00:00

I call an instance to a class in my main.m to my Controls.m class

  • 0

I call an instance to a class in my main.m to my Controls.m class but it seems to be giving me a “Unrecognized selector sent to instance” error. Any idea what I am doing wrong here? Every time I hit the button it just crashes, but isn’t Controls.m set to self in this code? It shouldn’t have trouble finding the test selector action.

Main.m

- (void)loadView {
    Controls *ct = [[Controls alloc] init];
    [ct addControls];
    [ct release];
}

Controls.m

- (void)addControls {
    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, mv.frame.size.height-60, mv.frame.size.width, 40)];
    UIBarButtonItem *barBtnDataOverlay = [[UIBarButtonItem alloc] initWithTitle:@"Test Button" style:UIBarButtonSystemItemAction target:self action:@selector(test)];
    NSArray *toolbarButtons = [[NSArray alloc] initWithObjects:barBtnDataOverlay, nil];
    toolbar.items = toolbarButtons;
    [mv addSubview:toolbar];
    [barBtnDataOverlay release];
    [toolbar release];
 }

- (void)test {
    NSLog(@"TEST button hit");
}
  • 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-26T04:21:32+00:00Added an answer on May 26, 2026 at 4:21 am

    ct will be dealloced by [ct release] as no retain is left. Try to add a ct retin property to your class to keep it around.

    In class definition:

    @property(nonatomic, retain) Controls *ct;
    

    In your implementation:

    @synthesize ct;
    

    …

    Change your loadView to something like:

    - (void)loadView {
        self.ct = [[Controls alloc] init];
        [self.ct addControls];
        [self.ct release];
    }
    

    Or even neater:

    - (void)loadView {
        self.ct = [[[Controls alloc] init] autorelease];
        [self.ct addControls];
    }
    

    You should also release ct somewhere like in viewDidUnload

    - (void)viewDidUnLoad {
        self.ct = nil;
    }
    

    BTW, is this in a UIViewController class? then the loadView method should probably assign the view instance variable. If you look in the documentation for UIViewController you will see this:

    If you override this method in order to create your views manually, you should do so and assign the root view of your hierarchy to the view property.

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

Sidebar

Related Questions

When I call as instance method of a class as follows : object_name.function_name(); how
I'm trying to call a custom instance of a 403 HTTP error in Rails
Call me a 'n00b', but I am new to creating Script Controls. I want
Is it possible to make the scope of an instance of a main class
In my main Actionscript file i have a instance of a body class that
What is the best way to call an instance method within an Expression Tree?
When I call a static method like: Something.action(); Since a instance isn't created how
When I call getBean(name) on a BeanFactory , I get back an instance of
When I receive XML data (via a Twitter API call, in this instance), I
I am using a third-party application, and making a call to create an instance

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.