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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:57:39+00:00 2026-06-04T14:57:39+00:00

I created a brand new project and created a new view controller with a

  • 0

I created a brand new project and created a new view controller with a button in the view.

I am adding the view in application:didFinishLaunchingWithOptions

- (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];


    BOOL introDisplayed = [[NSUserDefaults standardUserDefaults] boolForKey:kIntroScreenSeenByUser];

    if(introDisplayed)
    {

    }
    else 
    {
        IntroView *introView = [[IntroView alloc] initWithNibName:@"IntroView" bundle:nil];
        [self.window addSubview:introView.view];
    }

    [self.window makeKeyAndVisible];

    return YES;
}

.h file

@interface IntroView : UIViewController 


@property (weak, nonatomic) IBOutlet UIButton *clickMe;
- (IBAction)clicked:(id)sender;

@end

.m file

#import "IntroView.h"

@interface IntroView ()
@end

@implementation IntroView
@synthesize clickMe;

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

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

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

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (IBAction)clicked:(id)sender {
    NSLog(@"clicked");
}
@end

Clicking on the button results in a EXC_BAD_ACCESS(code=2 error. Any ideas? I am using ARC.

Thanks

UPDATE

Created a public property on the application delegate called “introViewController” and changed the application:didFinishLaunchingWithOptions

@synthesize introViewController;

- (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];


    BOOL introDisplayed = [[NSUserDefaults standardUserDefaults] boolForKey:kIntroScreenSeenByUser];

    introViewController = [[IntroView alloc] initWithNibName:@"IntroView" bundle:nil];
    if(introDisplayed)
    {

    }
    else 
    {
        [self.window addSubview:introViewController.view];
    }

    [self.window makeKeyAndVisible];

    return YES;
}

This solved the error.

  • 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-04T14:57:40+00:00Added an answer on June 4, 2026 at 2:57 pm

    You’re creating your IntroView controller, and adding it’s view as a subview, but the controller itself is released. I don’t think that adding the view controller’s view (and then letting ARC discard the controller itself) is an acceptable way to create a view.

    Perhaps you could make the IntroView view controller a property of the app delegate class and therefore it won’t be released by ARC.

    Personally, I don’t monkey around with the app delegate’s creation of the views and controllers, but rather I let my target settings and my NIBs dictate that. I presume you’re doing this because you want to have some intro screen. If I wanted an screen, I’d have my main view controller go ahead and present whatever intro I want. That way when the intro is dismissed (or popped off, depending upon whether you pushed or presented modally), my main view controller is still at the top (and useful methods like popToRootViewController work perfectly).

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

Sidebar

Related Questions

I created a brand new project using the default Web Application template and I
I created a brand new view-based project and added into the viewDidLoad - (void)viewDidLoad
i am using asp.net framework 4 and i have created brand new project and
This is weird. I added a brand new Web Application project to my solution
In a brand new iOS project using Xcode 4.3.2, if a button has an
I created a project in flex builder with application server type set to none.
I have a brand new Rails 3.1rc4 project. After generating a scaffold, migrating and
So I have been trying to create a new RESTfull web application project in
I followed the following instructions to start a brand new project in eclipse http://code.google.com/webtoolkit/usingeclipse.html
I created a brand new blank Visual Studio 2010 solution, and added an existing

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.