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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:50:28+00:00 2026-05-26T16:50:28+00:00

I just started building an app using X-Code 4.2. I created the app with

  • 0

I just started building an app using X-Code 4.2. I created the app with the single view application template.

I created a MainIconViewController which is a simple VC which contains an image, label and button. I add the MainIconViewController view to my mainViewController view and when the button is pressed I get a crash in Main.m that says:

-[__NSCFType mainButtonPressed:]: unrecognized selector sent to instance 0xb867ba0

The line in Main.m where the crash occurs is:

return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

right now buttonPressed: is completely empty.

Any ideas how to fix this?

I just tried making a whole new project to re-test this. I created the project, created a viewController subclass that contained a single button. I then create an instance of this view in the main view controller and add it to the view. When I press the button, the application crashes just like before.

EDIT:
Here’s All the code:

//MainIconViewController.h
@protocol MainIconViewControllerDelegate <NSObject>

-(void) openFileNamed:(NSString *)name;
-(void) createNewFile;

@end

#import <UIKit/UIKit.h>

@interface MainIconViewController : UIViewController {


}
@property (assign) id <MainIconViewControllerDelegate> delegate;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIImageView *imageView;
- (void)mainButtonPressed:(id)sender;


@end


//////////////////////////////
//MainIconViewController.m
#import "MainIconViewController.h"

@implementation MainIconViewController
@synthesize titleLabel;
@synthesize imageView;
@synthesize delegate;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{

    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [self setTitleLabel:nil];
    [self setImageView:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return YES;
}
- (void)mainButtonPressed:(id)sender{

}

@end
  • 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-26T16:50:28+00:00Added an answer on May 26, 2026 at 4:50 pm

    First your method have to be declared like this :

    - (IBAction)mainButtonPressed:(id)sender;
    

    Then you must call your controller like this :

    MainIconViewController *icon = [[MainIconViewController alloc]initWithNibName:@"your xib name without extension" bundle:nil];
    

    (safer, but that’s ok if your xib file is named like the controller)

    And of course, don’t forget to link you button into IB with the action.

    Check also that your File's owner (into IB) for the xib that corresponds to MainIconViewController is set to MainIconViewController.

    Note that you here have a memory leak. You may retain the controller in your class and release it whne not needed anymore. If release too early, it will crash because your view does not have a controller in memory when needed. If not released (like here you do), the controller keeps staying in memory and you have a memory leak.

    Note that the way you do is not recommended by Apple (one view hierarchy = one view controller). If you use ARC, that could be the problem of your crash.

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

Sidebar

Related Questions

I have just started building a app using XihSolutions.DotMSN.dll version: 2.0.0.40909, My problem is
I've just started out building a very simple score screen for my app but
I've just started building an api and application that consumes from the api using
I have just started building my first Flask app, which currently simply returns output
I am just getting started learning rails. I am building my first app using
I've just started building a prototype application in Django. I started out by working
I've just started using the MVP pattern in the large ASP.NET application that I'm
I have recently started building an application in rails (3.0.5). Just to get things
Just started learning mvc3. I've built a fairly basic website (also using EF-Code-First if
i just started building a small test app to help me learn MVC. i

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.