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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T23:33:35+00:00 2026-05-30T23:33:35+00:00

I am having a problem setting the target for a UIButton: // TestViewController.m @implementation

  • 0

I am having a problem setting the target for a UIButton:

//  TestViewController.m
@implementation TestViewController

@synthesize scrollContentView

- (void)viewDidLoad
{
    [super viewDidLoad];
 SecondViewController *secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];

[self.scrollContentView addSubview:secondViewController.view];
}

@end

// SecondViewController.m
- (void)viewDidLoad
{
    [super viewDidLoad];
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [button1 addTarget:self action:@selector(button1Click:) forControlEvents:UIControlEventTouchUpInside];
    button1.frame = CGRectMake(20, 45, 280, 40);
    [self.view addSubview:button1];
}

- (IBAction)button1Click:(id)sender
{
    NSLog(@"test");
}

The issue is when I click on the button I get the following error message:

[SecondViewController performSelector:withObject:withObject:]: message
sent to deallocated instance 0x685c050

(lldb)

I am assuming that the issue is I am passing just a view into the UIScrollView and I cannot access the controller.

Any idea how to solve 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-05-30T23:33:37+00:00Added an answer on May 30, 2026 at 11:33 pm

    The message “message sent to deallocated instance” means that your secondViewController variable was not retained when the variable went out of scope at the end of viewDidLoad
    however it’s view, which contains it’s button, was. Leading to a live object with a pointer to a dead object. Thus your crash.

    Since you’re using ARC, the quickest (possibly hackie) way would be to make the SecondViewController in ivar of TestViewController.

    @implementation TestViewController{
        SecondViewController *secondViewController; // with ARC ivars are strong by default
    }
    

    And then change the line in viewDidLoad to:

    secondViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
    

    But I believe that the correct way (of course I don’t know the specifics of your app) would probably be to use:

    - (void)addChildViewController:(UIViewController *)childController __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_5_0);
    

    A word of caution if this is an iPhone/iPod touch app; Apple has said for these devices the ratio should generally be one view controller to one screen of content. Again I don’t know the specifics of your app, just wanted to mention it.

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

Sidebar

Related Questions

I am having problem with the XCode->Project->Edit Active Target projectname setting I am trying
I am having a problem setting the Authorize attribute Role value from a variable.
I'm having a problem setting a cookie and doing a 302 redirect In chrome
I am having a problem setting up the following in Visual Studio 2008: a
I am having a problem setting the background of UITableView to a UIImageView (see
I am having a problem where a cookie I am setting is being lost
I am in the process of setting up CruiseControl.NET. The problem I am having
I'm having a problem setting the font for UILabels and UITextViews with Interface Builder.
I am having a little bit of a problem with setting up a mysql
I'm having a problem setting up an event on a form. Here's the setup:

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.