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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:06:22+00:00 2026-06-04T22:06:22+00:00

I am programmatically creating a view in the loadView method of my view controller.

  • 0

I am programmatically creating a view in the loadView method of my view controller. As follows:

-(void)loadView {

HPSFormView* viewForThisController = [ [ HPSFormView alloc ] initWithFrame:CGRectZero ] ;
viewForThisController.controller = self; // Set a reference back to this controller so the View knows who to delegate stuff to when > adding controls
self.view = viewForThisController; // Set the view for this controller to be the main menu view 

}

I follow this technique for three different pairs of view controllers and views. I am pushing the view controllers onto a UINavigationController stack. Each view contains a button that uses push. As follows:

-(void)buttonTapped:(id)sender  {
    HPSFormController* formVC = [ [ HPSFormController alloc ] initWithNibName:nil bundle:nil ];
    [(UINavigationController*) self.view.window.rootViewController pushViewController:formVC animated:YES]; 
}

I do not have any code in viewDidLoad – indeed, it is entirely absent from my view controllers.

Everything works fine, but when I do a Simulate Memory Warning within the iOS simulator then the app crashes. I believe the problem lies with the way that I am defining my view as a ‘local’ variable within loadView.

Could anyone tell me whether my loadView looks ok, or whether it is necessary to define loadView differently to avoid invalid references etc.

Many thanks.

  • 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-04T22:06:23+00:00Added an answer on June 4, 2026 at 10:06 pm

    The problem was that the view was holding a reference to the controller. When the view was unloaded then the controller reference went out of scope, so boom!

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

Sidebar

Related Questions

I'm current creating a UISegmentedControl programmatically in a view controller's viewDidLoad method and adding
I'm programmatically creating a folder using C# and need to set the default view
I am creating a view controller programmatically which is a UITabBarDelegate and contains a
In my view controller I'm programmatically creating N buttons in my UIView . Each
I'm creating my view hierarchy programmatically in loadView in my ViewController. I have to
I'm creating several menu items programmatically like this : NSMenuItem* newItem = [[NSMenuItem alloc]
I am creating 2 buttons programmatically in my view. Both selector methods exist but
I am creating a section view programmatically and I have a UIButton delete also
I'm programmatically creating a tab bar based app. In the application:didFinishLaunchingWithOptions (app delegate) method
I am creating table rows programmatically and i want to put a view that

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.