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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T17:49:24+00:00 2026-06-06T17:49:24+00:00

I am a total beginner to Objective C. Currently I try to display a

  • 0

I am a total beginner to Objective C.

Currently I try to display a view in my main window. This view contains a button. For some reason by clicking this button xcode throws an error.

Hopefully you can help me to understand what I am doing wrong.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];

    BtnView *btn = [[BtnView alloc] init];
    [self.window addSubview:btn.view];        
    [self.window makeKeyAndVisible];

    return YES;
}

The viewController of my button view has an action for recognizing a touch up event
h file:

- (IBAction)touched:(id)sender;

and in the m file

- (IBAction)touched:(id)sender {
    //actions ...
}

By touching the button I get the following error:

enter image description here
Whats wrong?

m file:

enter image description here

h file:
enter image description here

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

    I assume you have ARC enabled for this project.

    When you return from didFinishLaunchingWithOptions: the object assigned to btn will be released since you assign it to a local variable that is only defined within that method. Make BtnView *btn a strong property of your class and it should stay around to handle the button presses. (Remember to use self.btn in references to it.)

    (But, I’m curious, why not just put the button on your main view in the first place and then not worry about an extra controller and subviews?)

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

Sidebar

Related Questions

To start let me tell you I am a total Objective-C beginner. This is
I'm a total beginner so I apologize if this question is elementary. I have
Ok. So I am a total beginner at Java. But why does this loop
Let me preface this post with a single caution. I am a total beginner
Total beginner question about jQuery: I have a Form that contains several TextBoxes (input
I'm a total beginner to matlab and I'm currently writing a script for extracting
Okay so I'm a total beginner at programming and this is my first programming
I am trying to use VIM for some programming. I am a total beginner
This is a total beginner question, I've spent the past hour searching both stackoverflow
I am a total beginner in both simulations so this question might be silly.

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.