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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:35:45+00:00 2026-05-13T06:35:45+00:00

Assuming I load a view controller from a nib, and decide to do something

  • 0

Assuming I load a view controller from a nib, and decide to do something with one of its subview behind the scene. At a later moment in time, I would show the view of this view controller.

viewController = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil]; 
[viewController.someSubview doSomething];

//later on 
[mainView addSubview:viewController.view];

The problem is that, the someSubview object doesn’t seem to be loaded until the view appears, so the method doSomething is not called. So far my workaround is to call:

[mainView addSubview:viewController.view];
[viewController.view removeFromSuperview];

to initialize the subviews of viewcontroller first. Is there any more elegant way (like a loadSubviews method or something) for this task?

  • 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-13T06:35:46+00:00Added an answer on May 13, 2026 at 6:35 am

    First of all I would try simply accessing the property:

    [viewController view];
    

    This will force the lazy load of the view (and thus the subviews and outlets etc.) and this might be enough for you. View controllers by default will not load their view until you access it so this might be why you are seeing a delay.

    Forcing a load like this is usually the solution when you are trying to access an outlet property but it hasn’t actually been bound yet, like someSubview in your case.

    You can also improve things a bit by adding the view but making it hidden:

    viewController.view.hidden = YES;
    [mainView addSubview:viewController.view];
    

    Then instead of calling addSubview when you want to show it, just do:

    viewController.view.hidden = NO;
    

    I’ve used this method when animating in views using the UIViewAnimationTransitionFlipFromRight etc. transitions. Even when forcing a lazy load of the view there is still a noticable lag, so I’ve used this to improve the performance a bit.

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

Sidebar

Ask A Question

Stats

  • Questions 306k
  • Answers 306k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If your colleagues are writing out their SQL statements, there's… May 13, 2026 at 9:20 pm
  • Editorial Team
    Editorial Team added an answer I think the problem is that you are using $query… May 13, 2026 at 9:20 pm
  • Editorial Team
    Editorial Team added an answer These are C solutions: Are you just trying to parse… May 13, 2026 at 9:20 pm

Related Questions

Suppose I want entries in the table Regions to have a type, e.g. a
I'm looking to build a scalable database solution for the back end of my
I'm creating a calendar that displays a timetable of events for a month. Each
This is a continuation of the question posted in: How to load a jar
I have the following line of code in VS2008. VirtualPathData virtualPathData = RouteTable.Routes.GetVirtualPath(_viewContext.RequestContext, Home,

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.