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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:40:38+00:00 2026-05-20T06:40:38+00:00

I am basically trying to add two view controllers to one controller. I created

  • 0

I am basically trying to add two view controllers to one controller.

I created a view based application called “MultipleViews”. After that i add two controller classes “RedView.h” and “BlueView.h” with their own xibs. I am able to add the views of both the controllers to “MutipleViewsViewController” by the method [self.view addSubview:red.view]. Both the views are displayed properly. The problem is when I add a button to the red and blue controllers. Whenever I click the button it says unrecognized selector sent to instance even though I linked the buttons with their functions properly. Am i missing something here?

here is the code:

MultipleViewsViewController.h

#import <UIKit/UIKit.h>

@interface MutipleViewsViewController : UIViewController {

}

@end

MutipleViewsViewController.m

–

 (void)viewDidLoad {
    [super viewDidLoad];

    RedView *red = [[RedView alloc]init];

    red.view.frame = CGRectMake(0, 0, 320, 240);

    [self.view addSubview:red.view];

    BlueView *blue = [[BlueView alloc]init];

    blue.view.frame = CGRectMake(0, 240, 320, 240);

    [self.view addSubview:blue.view];



}

RedView.h

#import <UIKit/UIKit.h>


@interface RedView : UIViewController {

}

-(IBAction)buttonPressed;

@end

BlueView.h

#import <UIKit/UIKit.h>


@interface BlueView : UIViewController {

}

-(IBAction)buttonPressed;

@end

The buttons are linked to the buttonPressed method through IB.
The message i get when i click the button in the red view is:

MutipleViews[1865:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RedView buttonPressed]: unrecognized selector sent to instance 0x4e12500'

Sorry for not being clear earlier.



  • 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-20T06:40:39+00:00Added an answer on May 20, 2026 at 6:40 am

    The IBActions typically take an input parameter of type id. So your buttonPressed action should look like

    -(IBAction)buttonPressed:(id)sender;
    

    When this action is actually called, a reference to the control which calls it (in this case the button) is passed.

    When calling it programatically, you can send the controller’s object (self) to it.

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

Sidebar

Related Questions

I am trying to write an Add-In to PowerPoint that does basically one thing:
I am trying to create a job application-form with Django. Basically, I created two
I'm trying to create simple function that will work two ways. Basically, when I
I'm trying to add two loops to a theme on two separate pages: home
Short Question: Basically I am trying to add a scalar property to my entity
I'm trying to create two a regex to add quotes to some values in
I'm trying to make argparse ignore the fact that two normally required positional arguments
I'm trying to build two webservices with WCF (VS2010). One webservice runs fine, but
I'm basically trying to figure out the simplest way to perform your basic insert
I'm basically trying to teach myself how to code and I want to follow

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.